assafgi / python-twitter

Automatically exported from code.google.com/p/python-twitter
Apache License 2.0
0 stars 0 forks source link

Parsing error when doing a UsersLookup on non-existing accounts #220

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
The UsersLookup call can take a list of screen_names and return info on all of 
them. If there are some bad (non-existant) accounts in the list, it just 
quietly omits them from the response. When *all* of the names are bad, an error 
response is returned that looks like:

    {u'errors': [{u'message': u'No user matches for specified terms', u'code': 17}]}

However, the UsersLookup call doesn't account for this possibility; line 3049 
will automatically try to create a new user from the list it expects to get 
back:

    return [User.NewFromJsonDict(u) for u in data]

Therefore, in the unfortunate situation of an entirely non-existant list, 
python-twitter will crash with a completely unhelpful error:

    Traceback (most recent call last):
      File "id.py", line 45, in <module>
        users = twitterApi.UsersLookup(screen_name=userSublist)
      File "/Users/apetresc/.virtualenv/twitsprout/lib/python2.7/site-packages/twitter.py", line 3049, in UsersLookup
        return [User.NewFromJsonDict(u) for u in data]
      File "/Users/apetresc/.virtualenv/twitsprout/lib/python2.7/site-packages/twitter.py", line 1340, in NewFromJsonDict
        return User(id=data.get('id', None),
    AttributeError: 'unicode' object has no attribute 'get'

It should instead check for data['errors'] and deal with that accordingly.

Original issue reported on code.google.com by apetresc on 3 Dec 2011 at 5:41

GoogleCodeExporter commented 9 years ago
Well isn't that special, looks like Twitter has changed how errors are 
returned.  

Well it's different than what the code is currently checking for:

    if 'error' in data:
      raise TwitterError(data['error'])

maybe Twitter introduced 'errors' for the list form? *shrug*, will adjust the 
code.

thanks for the report!

Original comment by bear42 on 3 Dec 2011 at 9:08

GoogleCodeExporter commented 9 years ago
committed changeset 235:cec8703b7782

Original comment by bear42 on 3 Dec 2011 at 9:29