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:
|
if size:
|
||||||
url = self.constructApiURL(url, {'size':size})
|
url = self.constructApiURL(url, {'size':size})
|
||||||
|
|
||||||
try:
|
|
||||||
client = httplib2.Http()
|
client = httplib2.Http()
|
||||||
client.follow_redirects = False
|
client.follow_redirects = False
|
||||||
resp = client.request(url, 'HEAD')[0]
|
resp, content = client.request(url, 'GET')
|
||||||
if resp['status'] not in ('301', '302', '303', '307'):
|
|
||||||
raise TwythonError("getProfileImageUrl() failed to get redirect.")
|
|
||||||
return resp['location']
|
|
||||||
|
|
||||||
except HTTPError, e:
|
if resp.status in (301,302,303,307):
|
||||||
raise TwythonError("getProfileImageUrl() failed with a %d error code." % e.code, e.code)
|
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
|
@staticmethod
|
||||||
def encode_multipart_formdata(fields, files):
|
def encode_multipart_formdata(fields, files):
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue