Urllib's urlopen breaking on some sites (e.g. StackApps api): returns garbage results
Posted
by Edan Maor
on Stack Overflow
See other posts from Stack Overflow
or by Edan Maor
Published on 2010-06-12T10:58:16Z
Indexed on
2010/06/13
7:12 UTC
Read the original article
Hit count: 512
I'm using urllib2
's urlopen
function to try and get a JSON result from the StackOverflow api.
The code I'm using:
>>> import urllib2
>>> conn = urllib2.urlopen("http://api.stackoverflow.com/0.8/users/")
>>> conn.readline()
The result I'm getting:
'\x1f\x8b\x08\x00\x00\x00\x00\x00\x04\x00\xed\xbd\x07`\x1cI\x96%&/m\xca{\x7fJ\...
I'm fairly new to urllib, but this doesn't seem like the result I should be getting. I've tried it in other places and I get what I expect (the same as visiting the address with a browser gives me: a JSON object).
Using urlopen
on other sites (e.g. "http://google.com") works fine, and gives me actual html. I've also tried using urllib
and it gives the same result.
I'm pretty stuck, not even knowing where to look to solve this problem. Any ideas?
© Stack Overflow or respective owner