]> jfr.im git - z_archive/twitter.git/blobdiff - twitter/api.py
Handling errors in TwitterHTTPError __init__
[z_archive/twitter.git] / twitter / api.py
index c61ffc50c56883a48ac048f13c0b2a2f8cd9fac1..daa3a2bfdb58ccd70b144edb9e482f019a4542c5 100644 (file)
@@ -42,12 +42,18 @@ class TwitterHTTPError(TwitterError):
         self.uri = uri
         self.format = format
         self.uriparts = uriparts
+        try:
+            data = self.e.fp.read()
+        except httplib.IncompleteRead, e:
+            # can't read the error text
+            # let's try some of it
+            data = e.partial
         if self.e.headers['Content-Encoding'] == 'gzip':
-            buf = StringIO(self.e.fp.read())
+            buf = StringIO(data)
             f = gzip.GzipFile(fileobj=buf)
             self.response_data = f.read()
         else:
-            self.response_data = self.e.fp.read()
+            self.response_data = data
 
     def __str__(self):
         fmt = ("." + self.format) if self.format else ""