gpt4 book ai didi

python - 调试 Python Instagram API 客户端 - 'NoneType' 没有 len()

转载 作者:行者123 更新时间:2023-12-01 04:41:58 25 4
gpt4 key购买 nike

这里是 Python 新手,所以请耐心等待...

我正在尝试使用 Python client for Instagram API ,并且在将 token 传递到 InstagramAPI 构造函数时输入有效的访问 token 和用户 ID(是的,我正在运行插入了访问 token 和用户 ID 的代码,但没有发布问题):

from instagram.client import InstagramAPI

access_token = "YOUR_ACCESS_TOKEN"
api = InstagramAPI(access_token=access_token)
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 "<stdin>", line 1, in <module>
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/instagram/bind.py", line 196, in _call
return method.execute()
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/instagram/bind.py", line 182, in execute
include_secret=self.include_secret)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/instagram/oauth2.py", line 224, in prepare_request
url = self._full_url_with_params(path, params, include_secret)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/instagram/oauth2.py", line 148, in _full_url_with_params
self._full_query_with_params(params) +
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/instagram/oauth2.py", line 144, in _full_url
self._signed_request(path, {}, include_signed_request, include_secret))
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/instagram/oauth2.py", line 172, in _signed_request
return "&sig=%s" % self._generate_sig(path, params, self.api.client_secret)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/instagram/oauth2.py", line 127, in _generate_sig
return hmac.new(secret, sig, sha256).hexdigest()
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/hmac.py", line 136, in new
return HMAC(key, msg, digestmod)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/hmac.py", line 71, in __init__
if len(key) > blocksize:
TypeError: object of type 'NoneType' has no len()

关于如何调试此错误有什么建议吗?具体来说,这个错误的可能来源是什么?

TypeError: object of type 'NoneType' has no len()

最佳答案

您遇到了一个错误,因为 github 上的文档(自述文件)不是最新的。仔细阅读此问题以找到您的解决方案

Missing argument for InstagramAPI object instance

OAuth Signing is broken in 1.3.1

你的代码应该是:

from instagram.client import InstagramAPI 

access_token = "YOUR_ACCESS_TOKEN"
client_secret = "YOUR_CLIENT_SECRET"
api = InstagramAPI(client_secret=client_secret, access_token=access_token)

关于python - 调试 Python Instagram API 客户端 - 'NoneType' 没有 len(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30442663/

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