class documentation

class Response(object):

View In Hierarchy

The Response object, which contains a server's response to an HTTP request.
Method __bool__ Returns True if status_code is less than 400.
Method __enter__ Undocumented
Method __exit__ Undocumented
Method __getstate__ Undocumented
Method __init__ Undocumented
Method __iter__ Allows you to use a response as an iterator.
Method __nonzero__ Returns True if status_code is less than 400.
Method __repr__ Undocumented
Method __setstate__ Undocumented
Method close Releases the connection back to the pool. Once this method has been called the underlying raw object must not be accessed again.
Method iter​_content No summary
Method iter​_lines Iterates over the response data, one line at a time. When stream=True is set on the request, this avoids reading the content at once into memory for large responses.
Method json Returns the json-encoded content of a response, if any.
Method raise​_for​_status Raises HTTPError, if one occurred.
Class Variable __attrs__ Undocumented
Instance Variable ​_content Undocumented
Instance Variable ​_content​_consumed Undocumented
Instance Variable ​_next Undocumented
Instance Variable cookies Undocumented
Instance Variable elapsed Undocumented
Instance Variable encoding Undocumented
Instance Variable headers Undocumented
Instance Variable history Undocumented
Instance Variable raw Undocumented
Instance Variable reason Undocumented
Instance Variable request Undocumented
Instance Variable status​_code Undocumented
Instance Variable url Undocumented
Property apparent​_encoding The apparent encoding, provided by the charset_normalizer or chardet libraries.
Property content Content of the response, in bytes.
Property is​_permanent​_redirect True if this Response one of the permanent versions of redirect.
Property is​_redirect True if this Response is a well-formed HTTP redirect that could have been processed automatically (by Session.resolve_redirects).
Property links Returns the parsed header links of the response, if any.
Property next Returns a PreparedRequest for the next request in a redirect chain, if there is one.
Property ok Returns True if status_code is less than 400, False if not.
Property text Content of the response, in unicode.
def __bool__(self):

Returns True if status_code is less than 400.

This attribute checks if the status code of the response is between 400 and 600 to see if there was a client error or a server error. If the status code, is between 200 and 400, this will return True. This is not a check to see if the response code is 200 OK.

def __enter__(self):

Undocumented

def __exit__(self, *args):

Undocumented

def __getstate__(self):

Undocumented

def __init__(self):

Undocumented

def __iter__(self):
Allows you to use a response as an iterator.
def __nonzero__(self):

Returns True if status_code is less than 400.

This attribute checks if the status code of the response is between 400 and 600 to see if there was a client error or a server error. If the status code, is between 200 and 400, this will return True. This is not a check to see if the response code is 200 OK.

def __repr__(self):

Undocumented

def __setstate__(self, state):

Undocumented

def close(self):

Releases the connection back to the pool. Once this method has been called the underlying raw object must not be accessed again.

Note: Should not normally need to be called explicitly.

def iter_content(self, chunk_size=1, decode_unicode=False):

Iterates over the response data. When stream=True is set on the request, this avoids reading the content at once into memory for large responses. The chunk size is the number of bytes it should read into memory. This is not necessarily the length of each item returned as decoding can take place.

chunk_size must be of type int or None. A value of None will function differently depending on the value of stream. stream=True will read data as it arrives in whatever size the chunks are received. If stream=False, data is returned as a single chunk.

If decode_unicode is True, content will be decoded using the best available encoding based on the response.

def iter_lines(self, chunk_size=ITER_CHUNK_SIZE, decode_unicode=False, delimiter=None):

Iterates over the response data, one line at a time. When stream=True is set on the request, this avoids reading the content at once into memory for large responses.

Note

This method is not reentrant safe.

def json(self, **kwargs):
Returns the json-encoded content of a response, if any.
Parameters
**kwargsOptional arguments that json.loads takes.
Raises
requests.exceptions.JSONDecodeErrorIf the response body does not contain valid json.
def raise_for_status(self):
Raises HTTPError, if one occurred.
__attrs__: list[str] =

Undocumented

_content: bool =

Undocumented

_content_consumed: bool =

Undocumented

_next =

Undocumented

cookies =

Undocumented

elapsed =

Undocumented

encoding =

Undocumented

headers =

Undocumented

history: list =

Undocumented

raw =

Undocumented

reason =

Undocumented

request =

Undocumented

status_code =

Undocumented

url =

Undocumented

@property
apparent_encoding =
The apparent encoding, provided by the charset_normalizer or chardet libraries.
@property
content =
Content of the response, in bytes.
@property
is_permanent_redirect =
True if this Response one of the permanent versions of redirect.
@property
is_redirect =
True if this Response is a well-formed HTTP redirect that could have been processed automatically (by Session.resolve_redirects).
@property
links =
Returns the parsed header links of the response, if any.
@property
next =
Returns a PreparedRequest for the next request in a redirect chain, if there is one.
@property
ok =

Returns True if status_code is less than 400, False if not.

This attribute checks if the status code of the response is between 400 and 600 to see if there was a client error or a server error. If the status code is between 200 and 400, this will return True. This is not a check to see if the response code is 200 OK.

@property
text =

Content of the response, in unicode.

If Response.encoding is None, encoding will be guessed using charset_normalizer or chardet.

The encoding of the response content is determined based solely on HTTP headers, following RFC 2616 to the letter. If you can take advantage of non-HTTP knowledge to make a better guess at the encoding, you should set r.encoding appropriately before accessing this property.