Looks to me like your "urllib2.urlopen(url).read()" call
fails. UnboundLocalError means that 'rawtweets' wasn't assigned, and it is
only assigned if this call returns successfully.

Here is another example for this:
"""
>>> def raise_error():
...   raise ValueError("i'm an error")
...
>>> def look_ma_referenced_before_assignment():
...   try:
...     x = raise_error()
...   except ValueError, e:
...     print e
...   print x
...
>>> look_ma_referenced_before_assignment()
i'm an error
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "<stdin>", line 6, in look_ma_referenced_before_assignment
UnboundLocalError: local variable 'x' referenced before assignment
"""

So I would check if "urllib2.urlopen(url).read()" actually works. For
example:
- check if an error message is printed
- catch all errors, not just urllib2 errors.

cheers,
robert

On Wed, Aug 24, 2011 at 5:02 PM, theChips <[email protected]> wrote:

> I have no problem running my app on localhost, but when I deploy it I
> receive this error:
>
>
> 2011-08-24 16:55:57.464 Traceback (most recent call last):
> E 2011-08-24 16:55:57.464 File "/base/data/home/apps/
> s~brittanybermantweets/1.352785960472444569/web/application.py", line
> 237, in process
> E 2011-08-24 16:55:57.464 return self.handle()
> E 2011-08-24 16:55:57.464 File "/base/data/home/apps/
> s~brittanybermantweets/1.352785960472444569/web/application.py", line
> 228, in handle
> E 2011-08-24 16:55:57.464 return self._delegate(fn, self.fvars, args)
> E 2011-08-24 16:55:57.464 File "/base/data/home/apps/
> s~brittanybermantweets/1.352785960472444569/web/application.py", line
> 409, in _delegate
> E 2011-08-24 16:55:57.464 return handle_class(cls)
> E 2011-08-24 16:55:57.464 File "/base/data/home/apps/
> s~brittanybermantweets/1.352785960472444569/web/application.py", line
> 385, in handle_class
> E 2011-08-24 16:55:57.464 return tocall(*args)
> E 2011-08-24 16:55:57.464 File "/base/data/home/apps/
> s~brittanybermantweets/1.352785960472444569/brittanyberman.py", line
> 18, in GET
> E 2011-08-24 16:55:57.464 tweets = brittanytweets.getTweets()
> E 2011-08-24 16:55:57.464 File "/base/data/home/apps/
> s~brittanybermantweets/1.352785960472444569/brittanytweets.py", line
> 16, in getTweets
> E 2011-08-24 16:55:57.464 tweets = json.loads(rawtweets)
> E 2011-08-24 16:55:57.464 UnboundLocalError: local variable
> 'rawtweets' referenced before assignment
>
>
> To make matters more confusing, it worked fine when I deployed it last
> night.
>
> Here is the python in question:
>
> import urllib2
> import simplejson as json
>
> url = "http://api.twitter.com/1/statuses/user_timeline.json?
> screen_name=brittanyberman"
>
>
> def getTweets():
>        try:
>                rawtweets = urllib2.urlopen(url).read()
>        except urllib2.HTTPError, e:
>                print "HTTP error: %d" % e.code
>        except urllib2.URLError, e:
>                print "Network error: %s" % e.reason.args[1]
>
>        alltweets=[]
>        tweets = json.loads(rawtweets)
>
>        for i in range(12):
>                alltweets.append(tweets[i]['text'])
>
>        #strip out the 'u' char
>        for i in range(len(alltweets)):
>                alltweets[i]=str(alltweets[i])
>
>        return alltweets
>
>
> The script runs fine on a local shell. Any idea what's wrong?
>
> Thanks!
>
> --
> You received this message because you are subscribed to the Google Groups
> "Google App Engine" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected].
> For more options, visit this group at
> http://groups.google.com/group/google-appengine?hl=en.
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Google App Engine" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/google-appengine?hl=en.

Reply via email to