mirror of
https://github.com/kennethreitz/requests3.git
synced 2026-06-05 23:10:16 +00:00
+9
-2
@@ -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."""
|
||||
|
||||
|
||||
Reference in New Issue
Block a user