1

This appears to be a very common error with a few different solutions, python: UnboundLocalError: local variable 'open' referenced before assignment

Python: Help with UnboundLocalError: local variable referenced before assignment

Where my question is different is that I don’t have a variable "resp" in the code I am running. Most of the other questions were posted because the poster used the same name for a class and variable or they failed to declare it as a global variable.

The Code

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

The Error

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

Any suggestions?

Community
  • 1
  • 1
Deepend
  • 4,057
  • 17
  • 60
  • 101

1 Answers1

7

Upgrade your tweepy library.

There was a bug when the request fails that would cause the specific error you see, but that has since been corrected. The fix is part of version 1.6 and up.

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
  • Hey Martijn I was running tweepy-1.7.1-py2.7.egg. i have now upgraded that to tweepy-1.9-py2.7.egg. However i think the PythonPath is now broken as its given me an "Unresolved import tweepy" - Traceback tweepy.error.TweepError: Failed to send request: [Errno 61] Connection refused – Deepend Jun 19 '12 at 15:38
  • "Unresolved import tweepy"? Sounds like PyDev, see [Pydev say, "Unresolved import" error](http://stackoverflow.com/q/7281955) the other error means your tweepy is now working, and you are getting a network error. – Martijn Pieters Jun 19 '12 at 15:40
  • 1
    Also, create new questions for new problems. – Martijn Pieters Jun 19 '12 at 15:40