调试Python Instagram API客户端 - 'NoneType'没有len() [英] Debugging Python Instagram API client - 'NoneType' has no len()

查看:197
本文介绍了调试Python Instagram API客户端 - 'NoneType'没有len()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我试图使用 Instagram API的API客户端,并且在将令牌传递到InstagramAPI构造函数时输入有效的访问令牌和用户ID(是的,我正在运行代码我的访问令牌和用户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)
in recent_media:
print media.caption.text

但在终端我不断得到这个错误:

 追溯(最近的最后一次呼叫):
文件< stdin>,第1行,< ;模块>
文件/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/instagram/bind.py,第196行,_call
return method.execute( )
文件/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/instagram/bind.py,第182行,执行
include_secret = self。 include_secret)
文件/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/instagram/oauth2.py,第224行,prepare_request
url = self ._full_url_with_params(path,params,include_secret)
文件/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/instagram/oauth2.py,第148行,_full_url_with_params
self._full_query_with_params(params)+
文件/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/instagram/oauth2.py,第144行,在_full_url
self._signed_request(path,{},include_signed_request,include_secret))
文件/ Library / Frameworks / Python.framework / Versions / 2.7 / lib / python2.7 / site-packages / instagram / oauth2.py,第172行,_signed_request
返回& sig =%s%self._generate_sig(path, params,self.api.client_secret)
文件/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/instagram/oauth2.py,第127行,_generate_sig
return hmac.new(secret,sig,sha256).hexdigest()
文件/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/hmac.py,第136行,新的
返回HMAC(键,msg,digestmod)
文件/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/hmac.py,第71行, __init__
如果len(key)> blockize:
TypeError:类型为NoneType的对象没有len()

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

  TypeError:类型为NoneType的对象没有len()
pre>

解决方案

您正面临一个错误,因为github上的doc(readme)不是最新的。仔细阅读此问题以找到您的解决方案



InstagramAPI对象实例的参数缺失



OAuth签名在1.3.1中被破坏



你的代码应该是:



$ _ code从instagram.client导入InstagramAPI

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


newbie to Python here, so bear with me...

I'm trying to use the Python client for Instagram API, and am entering a valid access token and user ID when passing the token into the InstagramAPI constructor (yes, I'm running the code with my access token and user ID inserted, but left out for posting the question):

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

but in terminal I keep getting this error:

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()

Any advice on how to debug this error? Specifically, what is the possible source of this error?

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

解决方案

you are facing a bug because the doc (readme) on github is not up-to-date. Read this issue carefully to find your solution

Missing argument for InstagramAPI object instance

OAuth Signing is broken in 1.3.1

your code should be:

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 Instagram API客户端 - 'NoneType'没有len()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆