Rewrote getProfileImageUrl to handle responses with status 200 (happen
when eg. a user does not exist)
This commit is contained in:
parent
66e7040df6
commit
1c12c9c7d5
1 changed files with 9 additions and 9 deletions
|
|
@ -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):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue