json errors

This commit is contained in:
Kenneth Reitz
2012-12-16 22:03:55 -05:00
parent 7ef6b6b682
commit 8b141b326a
2 changed files with 5 additions and 8 deletions
+1
View File
@@ -44,6 +44,7 @@ def request(method, url, **kwargs):
if session is None:
session = sessions.session(config=kwargs.get('config', None))
adhoc_session = True
# Todo, close sessions after?
return session.request(method=method, url=url, **kwargs)
+4 -8
View File
@@ -1048,14 +1048,10 @@ class Response(BaseResponse):
# a best guess).
encoding = guess_json_utf(self.content)
if encoding is not None:
try:
return json.loads(self.content.decode(encoding))
except (ValueError, UnicodeDecodeError):
pass
try:
return json.loads(self.text or self.content)
except ValueError:
return None
return json.loads(self.content.decode(encoding))
return json.loads(self.text or self.content)
@property
def links(self):