Safer error response handling.
authorKenneth Reitz <me@kennethreitz.com>
Mon, 21 Feb 2011 19:36:41 +0000 (14:36 -0500)
committerKenneth Reitz <me@kennethreitz.com>
Mon, 21 Feb 2011 19:36:41 +0000 (14:36 -0500)
requests/core.py

index 9292a9a..3f599b1 100644 (file)
@@ -134,10 +134,10 @@ class Request(object):
     def _build_response(self, resp):
         """Build internal Response object from given response."""
         
-        self.response.status_code = resp.code
-        self.response.headers = resp.info().dict
+        self.response.status_code = getattr(resp, 'code', None)
+        self.response.headers = getattr(resp.info(), 'dict', None)
+        self.response.url = getattr(resp, 'url', None)
         self.response.content = resp.read()
-        self.response.url = resp.url
 
     
     def send(self, anyway=False):