gpt4 book ai didi

python - 无法解析响应,不是有效的 JSON

转载 作者:行者123 更新时间:2023-11-28 18:32:52 24 4
gpt4 key购买 nike

我在尝试触发这行代码时收到此错误消息 (https://github.com/Instagram/python-instagram)

recent_media, next_ = api.user_recent_media(user_id="userid", count=10)

完整源代码

from instagram.client import InstagramAPI
import sys

# get access token
if len(sys.argv) > 1 and sys.argv[1] == 'local':
try:
from test_settings import *

InstagramAPI.host = test_host
InstagramAPI.base_path = test_base_path
InstagramAPI.access_token_field = "access_token"
InstagramAPI.authorize_url = test_authorize_url
InstagramAPI.access_token_url = test_access_token_url
InstagramAPI.protocol = test_protocol
except Exception:
pass

# Fix Python 2.x.
try:
import __builtin__
input = getattr(__builtin__, 'raw_input')
except (ImportError, AttributeError):
pass

client_id = input("Client ID: ").strip()
client_secret = input("Client Secret: ").strip()
redirect_uri = input("Redirect URI: ").strip()
raw_scope = input("Requested scope (separated by spaces, blank for just basic read): ").strip()
scope = raw_scope.split(' ')
# For basic, API seems to need to be set explicitly
if not scope or scope == [""]:
scope = ["basic"]

api = InstagramAPI(client_id=client_id, client_secret=client_secret, redirect_uri=redirect_uri)
redirect_uri = api.get_authorize_login_url(scope = scope)

print ("Visit this page and authorize access in your browser: "+ redirect_uri)

code = (str(input("Paste in code in query string after redirect: ").strip()))

access_token = api.exchange_code_for_access_token(code)

api = InstagramAPI(access_token=access_token[0], client_secret=client_secret)
recent_media, next_ = api.user_recent_media(user_id="userid", count=10)
for media in recent_media:
print media.caption.text

错误信息

Traceback (most recent call last):
File "python-instagram-stream.py", line 44, in <module>
recent_media, next_ = api.user_recent_media(user_id="userid", count=10)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/instagram/bind.py", line 197, in _call
return method.execute()
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/instagram/bind.py", line 189, in execute
content, next = self._do_api_request(url, method, body, headers)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/instagram/bind.py", line 131, in _do_api_request
raise InstagramClientError('Unable to parse response, not valid JSON.', status_code=response['status'])
instagram.bind.InstagramClientError: (400) Unable to parse response, not valid JSON.

我已经尝试过这个解决方案,但仍然产生相同的错误消息

instagram.bind.InstagramClientError: Unable to parse response, not valid JSON

我把它改成

api = InstagramAPI(access_token=access_token, client_secret=client_secret)

api = InstagramAPI(access_token=access_token[0], client_secret=client_secret)

最佳答案

最有可能的问题出在您对 api.user_recent_media 的调用中,如这一行所示:

recent_media, next_ = api.user_recent_media(user_id="userid", count=10)

具体来说,我怀疑 "userid" 是这里所期望的。

我会认为使用从调用中获得的值换行:

user_id = api.user_search('username')[0].id

将更有可能让您成功,其中 username 被相关的实际用户替换。

关于python - 无法解析响应,不是有效的 JSON,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35251935/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com