fixes #593
This commit is contained in:
Kenneth Reitz
2012-05-08 00:57:46 -04:00
parent 7b6338c4b6
commit fe7348cc53
+9 -2
View File
@@ -7,6 +7,7 @@ requests.models
This module contains the primary objects that power Requests.
"""
import json
import os
from datetime import datetime
@@ -796,8 +797,6 @@ class Response(object):
if self.encoding is None:
if chardet is not None:
encoding = chardet.detect(self.content)['encoding']
else:
raise ValueError("Can't detect page encoding.")
# Decode unicode from given encoding.
try:
@@ -811,6 +810,14 @@ class Response(object):
return content
@property
def json(self):
"""Returns the json-encoded content of a request, if any."""
try:
return json.loads(self.text or self.content)
except ValueError:
return None
def raise_for_status(self, allow_redirects=True):
"""Raises stored :class:`HTTPError` or :class:`URLError`, if one occurred."""