From 1c12c9c7d5eef574804a9b59ed453c9b9e2258a3 Mon Sep 17 00:00:00 2001 From: Erik Scheffers Date: Thu, 3 Feb 2011 18:02:33 +0800 Subject: [PATCH] Rewrote getProfileImageUrl to handle responses with status 200 (happen when eg. a user does not exist) --- twython/twython.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/twython/twython.py b/twython/twython.py index bec10e2..b8549fc 100644 --- a/twython/twython.py +++ b/twython/twython.py @@ -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.") + client = httplib2.Http() + client.follow_redirects = False + resp, content = client.request(url, 'GET') + + if resp.status in (301,302,303,307): return resp['location'] - - except HTTPError, e: - raise TwythonError("getProfileImageUrl() failed with a %d error code." % e.code, e.code) + 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):