Update twython.py (Attribute error, unicode object detected) #165

Merged
bkvirendra merged 1 commit from patch-2 into master 2013-04-08 13:38:24 -07:00
bkvirendra commented 2013-04-08 10:30:10 -07:00 (Migrated from github.com)

if unicode object is detected (instead of json) , convert it to json using simplejson/json.

if unicode object is detected (instead of json) , convert it to json using simplejson/json.
michaelhelmick commented 2013-04-08 10:33:13 -07:00 (Migrated from github.com)

Can you give an example when a unicode object would be detected?

Can you give an example when a unicode object would be detected?
bkvirendra commented 2013-04-08 10:42:09 -07:00 (Migrated from github.com)

while fetching the 'http://api.twitter.com/1.1/statuses/user_timeline.json'

I ve attached a screenshot with the response (the content variable)

Screenshot at 2013-04-08 23:11:10
Uploading Screenshot at 2013-04-08 23:11:58.png . . .

while fetching the 'http://api.twitter.com/1.1/statuses/user_timeline.json' I ve attached a screenshot with the response (the content variable) ![Screenshot at 2013-04-08 23:11:10](https://f.cloud.github.com/assets/1097043/352967/85e18a3e-a073-11e2-8c68-71bc03fe881b.png) ![Uploading Screenshot at 2013-04-08 23:11:58.png . . .]()
bkvirendra commented 2013-04-08 10:43:25 -07:00 (Migrated from github.com)

trying to decode it with simplejson after detecting unicode, solved it

    json_error = False
    try:
        try:
            # try to get json
            content = content.json()
        except AttributeError:
            # if unicode detected
            content = json.loads(content)
    except ValueError:
        json_error = True
        content = {}
trying to decode it with simplejson after detecting unicode, solved it ``` json_error = False try: try: # try to get json content = content.json() except AttributeError: # if unicode detected content = json.loads(content) except ValueError: json_error = True content = {} ```
michaelhelmick commented 2013-04-08 11:13:25 -07:00 (Migrated from github.com)

I don't understand how you received unicode?

I just did:

r = requests.get('http://api.twitter.com/1.1/statuses/user_timeline.json', auth=auth)
r.json()

and it didn't throw an Exception?

I don't understand how you received unicode? I just did: ``` python r = requests.get('http://api.twitter.com/1.1/statuses/user_timeline.json', auth=auth) r.json() ``` and it didn't throw an Exception?
bkvirendra commented 2013-04-08 11:21:04 -07:00 (Migrated from github.com)

On line 172 in twython.py you're trying to ?

 content = response.content.decode('utf-8')
On line 172 in twython.py you're trying to ? ``` content = response.content.decode('utf-8') ```
michaelhelmick commented 2013-04-08 11:23:05 -07:00 (Migrated from github.com)

I'm actually not sure why we're decoding that, let me ping @ryanmcgrath

I'm actually not sure why we're decoding that, let me ping @ryanmcgrath
bkvirendra commented 2013-04-08 11:24:08 -07:00 (Migrated from github.com)

okies!!

okies!!
michaelhelmick commented 2013-04-08 11:29:08 -07:00 (Migrated from github.com)

Gotcha gotcha! I replicated the error! Think you can update the version in setup.py and in twython.py both to 2.7.2 and I'll merge this in push to PyPi! :D

Gotcha gotcha! I replicated the error! Think you can update the version in `setup.py` and in `twython.py` both to 2.7.2 and I'll merge this in push to PyPi! :D
bkvirendra commented 2013-04-08 12:16:58 -07:00 (Migrated from github.com)

@michaelhelmick think I should I add my name to contributors list?

@michaelhelmick think I should I add my name to contributors list?
michaelhelmick commented 2013-04-08 12:48:15 -07:00 (Migrated from github.com)

You could do that too! I was going to do that in the 2.7.1 release but got lazy and didn't feel like looking up your info and links, sorry! 🍰 haha

You could do that too! I was going to do that in the 2.7.1 release but got lazy and didn't feel like looking up your info and links, sorry! :cake: haha
bkvirendra commented 2013-04-08 12:54:22 -07:00 (Migrated from github.com)

@michaelhelmick updated the version in twython.py and also the setup.py! I guess you can push this pypi now!

@michaelhelmick updated the version in twython.py and also the setup.py! I guess you can push this pypi now!
michaelhelmick commented 2013-04-08 13:41:48 -07:00 (Migrated from github.com)

Twython 2.7.2 is now available via PyPi!

`Twython` 2.7.2 is now available via PyPi!
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: code/twython#165
No description provided.