Rewrote getProfileImageUrl to handle responses with status 200 (happen

when eg. a user does not exist)
This commit is contained in:
Erik Scheffers 2011-02-03 18:02:33 +08:00 committed by Ryan McGrath
parent 66e7040df6
commit 1c12c9c7d5

View file

@ -417,16 +417,16 @@ class Twython(object):
if size:
url = self.constructApiURL(url, {'size':size})
try:
client = httplib2.Http()
client.follow_redirects = False
resp = client.request(url, 'HEAD')[0]
if resp['status'] not in ('301', '302', '303', '307'):
raise TwythonError("getProfileImageUrl() failed to get redirect.")
return resp['location']
resp, content = client.request(url, 'GET')
except HTTPError, e:
raise TwythonError("getProfileImageUrl() failed with a %d error code." % e.code, e.code)
if resp.status in (301,302,303,307):
return resp['location']
elif resp.status == 200:
return simplejson.loads(content)
raise TwythonError("getProfileImageUrl() failed with a %d error code." % resp.status, resp.status)
@staticmethod
def encode_multipart_formdata(fields, files):