response

Module Contents

Classes

DeflateDecoder(self)
HTTPResponse(self,body=”“,headers=None,status=0,version=0,reason=None,strict=0,preload_content=True,decode_content=True,original_response=None,pool=None,connection=None) HTTP Response container.

Functions

_get_decoder(mode)
class DeflateDecoder
__init__()
__getattr__(name)
decompress(data)
_get_decoder(mode)
class HTTPResponse(body="", headers=None, status=0, version=0, reason=None, strict=0, preload_content=True, decode_content=True, original_response=None, pool=None, connection=None)

HTTP Response container.

Backwards-compatible to httplib’s HTTPResponse but the response body is loaded and decoded on-demand when the data property is accessed. This class is also compatible with the Python standard library’s io module, and can hence be treated as a readable object in the context of that framework.

Extra parameters for behaviour not present in httplib.HTTPResponse:

Parameters:
  • preload_content – If True, the response’s body will be preloaded during construction.
  • decode_content – If True, attempts to decode specific content-encoding’s based on headers (like ‘gzip’ and ‘deflate’) will be skipped and raw data will be used instead.
  • original_response – When this HTTPResponse wrapper is generated from an httplib.HTTPResponse object, it’s convenient to include the original for debug purposes. It’s otherwise unused.
__init__(body="", headers=None, status=0, version=0, reason=None, strict=0, preload_content=True, decode_content=True, original_response=None, pool=None, connection=None)
get_redirect_location()

Should we redirect and where to?

Returns:Truthy redirect location string if we got a redirect status code and valid location. None if redirect status and no location. False if not a redirect status code.
release_conn()
data()
tell()

Obtain the number of bytes pulled over the wire so far. May differ from the amount of content returned by :meth:HTTPResponse.read if bytes are encoded on the wire (e.g, compressed).

read(amt=None, decode_content=None, cache_content=False)

Similar to httplib.HTTPResponse.read(), but with two additional parameters: decode_content and cache_content.

Parameters:
  • amt – How much of the content to read. If specified, caching is skipped because it doesn’t make sense to cache partial content as the full response.
  • decode_content – If True, will attempt to decode the body based on the ‘content-encoding’ header.
  • cache_content – If True, will save the returned data such that the same result is returned despite of the state of the underlying file object. This is useful if you want the .data property to continue working after having .read() the file object. (Overridden if amt is set.)
stream(amt=None, decode_content=None)

A generator wrapper for the read() method. A call will block until amt bytes have been read from the connection or until the connection is closed.

Parameters:
  • amt – How much of the content to read. The generator will return up to much data per iteration, but may return less. This is particularly likely when using compressed data. However, the empty string will never be returned.
  • decode_content – If True, will attempt to decode the body based on the ‘content-encoding’ header.
from_httplib(r, **response_kw)

Given an httplib.HTTPResponse instance r, return a corresponding urllib3.response.HTTPResponse object.

Remaining parameters are passed to the HTTPResponse constructor, along with original_response=r.

getheaders()
getheader(name, default=None)
close()
closed()
fileno()
flush()
readable()
readinto(b)