Skip to main content
 首页 » 编程设计

python之未绑定(bind)本地错误 : local variable 'resp' referenced before assignment

2025年05月04日14zhenyulu

这似乎是一个非常常见的错误,有几个不同的解决方案, python: UnboundLocalError: local variable 'open' referenced before assignment

Python: Help with UnboundLocalError: local variable referenced before assignment

我的问题不同之处在于我正在运行的代码中没有变量“resp”。大多数其他问题的发布是因为发布者对类和变量使用了相同的名称,或者他们没有将其声明为全局变量。

代码

import tweepy 
auth = tweepy.OAuthHandler('75VSSMGC4pfUB5u0Zt5G3Q', '2olQeiquDg71uwnGoU2c9e2u3qy2LrKkn2p6KWBIdI') 
auth.set_access_token('122095773-cCrYa4FWFoBkx44LES8yeBlt8DTG0jnZivJ79k2J', 'p1Nmp9DaPUIThpTamzIMfdvJu0wgdfxmghdwsSagM') 
api = tweepy.API(auth) 
 
print api.rate_limit_status() 
#print tweepy.api.rate_limit_status() 

错误

Traceback (most recent call last): 
  File "/Users/brendan/Documents/workspace/Tweeter/src/rate_limit.py", line 6, in <module> 
    print api.rate_limit_status() 
  File "build/bdist.macosx-10.5-fat3/egg/tweepy/binder.py", line 185, in _call 
  File "build/bdist.macosx-10.5-fat3/egg/tweepy/binder.py", line 147, in execute 
UnboundLocalError: local variable 'resp' referenced before assignment 

有什么建议吗?

请您参考如下方法:

升级您的 tweepy 库。

当请求失败时有一个错误会导致您看到的特定错误,但它有 since been corrected .该修复程序是 1.6 及更高版本的一部分。