â„– Clns/Grp Matched text
1 2 :param pool_connections: The number of urllib3 connection pools to cache. :param pool_maxsize: The maximum number of connections to save in the pool. {1}{2}
2 2 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. {1}{2}
3 5 This should not be called from user code, and is only exposed for use when subclassing the :class:`HTTPAdapter <requests.adapters.HTTPAdapter>` {1}{2}{3}{4}{5}
4 3 Unlike a regular CookieJar, this class is pickleable. {1}{2}{3}
5 3 This method should not be called from user code, and is only exposed for use when subclassing the :class:`HTTPAdapter <requests.adapters.HTTPAdapter>`. {1}{2}{3}
6 2 def get(url, **kwargs): Sends a GET request. Returns :class:`Response` object. :param url: URL for the new :class:`Request` object. :param \*\*kwargs: Optional arguments that ``request`` takes. def options(url, **kwargs): Sends a OPTIONS request. Returns :class:`Response` object. :param url: URL for the new :class:`Request` object. :param \*\*kwargs: Optional arguments that ``request`` takes. def head(url, **kwargs): Sends a HEAD request. Returns :class:`Response` object. :param url: URL for the new :class:`Request` object. :param \*\*kwargs: Optional arguments that ``request`` takes. def post(url, data=None, json=None, **kwargs): Sends a POST request. Returns :class:`Response` object. :param url: URL for the new :class:`Request` object. :param data: (optional) Dictionary, bytes, or file-like object to send in the body of the :class:`Request`. :param json: (optional) json data to send in the body of the :class:`Request`. :param \*\*kwargs: Optional arguments that ``request`` takes. def put(url, data=None, **kwargs): Sends a PUT request. Returns :class:`Response` object. :param url: URL for the new :class:`Request` object. :param data: (optional) Dictionary, bytes, or file-like object to send in the body of the :class:`Request`. :param \*\*kwargs: Optional arguments that ``request`` takes. def patch(url, data=None, **kwargs): Sends a PATCH request. Returns :class:`Response` object. :param url: URL for the new :class:`Request` object. :param data: (optional) Dictionary, bytes, or file-like object to send in the body of the :class:`Request`. :param \*\*kwargs: Optional arguments that ``request`` takes. def delete(url, **kwargs): Sends a DELETE request. Returns :class:`Response` object. :param url: URL for the new :class:`Request` object. :param \*\*kwargs: Optional arguments that ``request`` takes. {1}{2}
7 2 :param method: method for the new :class:`Request` object. :param url: URL for the new :class:`Request` object. :param params: (optional) Dictionary or bytes to be sent in the query string for the :class:`Request`. :param data: (optional) Dictionary, bytes, or file-like object to send in the body of the :class:`Request`. :param json: (optional) json data to send in the body of the :class:`Request`. :param headers: (optional) Dictionary of HTTP Headers to send with the :class:`Request`. :param cookies: (optional) Dict or CookieJar object to send with the :class:`Request`. :param files: (optional) Dictionary of ``'name': file-like-objects`` (or ``{'name': ('filename', fileobj)}``) for multipart encoding upload. :param auth: (optional) Auth tuple to enable Basic/Digest/Custom HTTP Auth. :param timeout: (optional) How long to wait for the server to send data before giving up, as a float, or a (`connect timeout, read timeout <user/advanced.html#timeouts>`_) tuple. :type timeout: float or tuple :param allow_redirects: (optional) Boolean. Set to True if POST/PUT/DELETE redirect following is allowed. :type allow_redirects: bool :param proxies: (optional) Dictionary mapping protocol to the URL of the proxy. :param verify: (optional) if ``True``, the SSL cert will be verified. A CA_BUNDLE path can also be provided. :param stream: (optional) if ``False``, the response content will be immediately downloaded. {1}{2}
8 2 def __getitem__(self, name): Dict-like __getitem__() for compatibility with client code. Throws exception if there are more than one cookie with name. In that case, use the more explicit get() method instead. Caution: operation is O(n), not O(1). {1}{2}
9 2 To create a header from the :class:`list` again, use the :func:`dump_header` function. :param value: a string with a list header. :return: :class:`list` {1}{2}
10 2 def get(self, name, default=None, domain=None, path=None): Dict-like get() that also supports optional domain and path args in order to resolve naming collisions from using one cookie jar over multiple domains. Caution: operation is O(n), not O(1). {1}{2}
11 3 Usage:: >>> import requests >>> req = requests.request('GET', 'http://httpbin.org/get') {1}{2}{3}
Blacklisted group descriptors: 2dict group descriptors: 2elem group descriptors:
Source code:
<?xml version="1.0" encoding="utf-8" ?>
<plainxml>class BaseAdapter(object):
The Base Transport Adapter

class HTTPAdapter(BaseAdapter):
The built-in HTTP Adapter for urllib3.

Provides a general-case interface for Requests sessions to contact HTTP and
HTTPS urls by implementing the Transport Adapter interface. This class will
usually be created by the :class:`Session &amp;lt;Session&amp;gt;` class under the
covers.

<!-- 2acebf81-4457-4ce1-a425-ef5192006366 <=< ACCEPT -->:param pool_connections: The number of urllib3 connection pools to cache.
:param pool_maxsize: The maximum number of connections to save in the pool.<!-- ACCEPT >=> 2acebf81-4457-4ce1-a425-ef5192006366 -->
:param int max_retries: The maximum number of retries each connection
should attempt. Note, this applies only to failed DNS lookups, socket
connections and connection timeouts, never to requests where data has
made it to the server. By default, Requests does not retry failed
connections. If you need granular control over the conditions under
which we retry a request, import urllib3's ``Retry`` class and pass
that instead.
:param pool_block: Whether the connection pool should block for connections.

Usage::

&amp;gt;&amp;gt;&amp;gt; import requests
&amp;gt;&amp;gt;&amp;gt; s = requests.Session()
&amp;gt;&amp;gt;&amp;gt; a = requests.adapters.HTTPAdapter(max_retries=3)
&amp;gt;&amp;gt;&amp;gt; s.mount('http://', a)

def init_poolmanager(self, connections, maxsize, block=DEFAULT_POOLBLOCK, **pool_kwargs):
Initializes a urllib3 PoolManager.

<!-- 6285e141-3fc3-4214-91f8-df15673cd165 <=< ACCEPT -->This method should not be called from user code, and is only
exposed for use when subclassing the
:class:`HTTPAdapter &amp;lt;requests.adapters.HTTPAdapter&amp;gt;`.<!-- ACCEPT >=> 6285e141-3fc3-4214-91f8-df15673cd165 -->

<!-- 2acebf81-4457-4ce1-a425-ef5192006366 <=< ACCEPT -->:param connections: The number of urllib3 connection pools to cache.
:param maxsize: The maximum number of connections to save in the pool.<!-- ACCEPT >=> 2acebf81-4457-4ce1-a425-ef5192006366 -->
:param block: Block when no free connections are available.
:param pool_kwargs: Extra keyword arguments used to initialize the Pool Manager.

def proxy_manager_for(self, proxy, **proxy_kwargs):
Return urllib3 ProxyManager for the given proxy.

<!-- 6285e141-3fc3-4214-91f8-df15673cd165 <=< ACCEPT -->This method should not be called from user code, and is only
exposed for use when subclassing the
:class:`HTTPAdapter &amp;lt;requests.adapters.HTTPAdapter&amp;gt;`.<!-- ACCEPT >=> 6285e141-3fc3-4214-91f8-df15673cd165 -->

:param proxy: The proxy to return a urllib3 ProxyManager for.
:param proxy_kwargs: Extra keyword arguments used to configure the Proxy Manager.
:returns: ProxyManager

def cert_verify(self, conn, url, verify, cert):
Verify a SSL certificate. <!-- 6285e141-3fc3-4214-91f8-df15673cd165 <=< ACCEPT -->This method should not be called from user
code, and is only exposed for use when subclassing the
:class:`HTTPAdapter &amp;lt;requests.adapters.HTTPAdapter&amp;gt;`.<!-- ACCEPT >=> 6285e141-3fc3-4214-91f8-df15673cd165 -->

:param conn: The urllib3 connection object associated with the cert.
:param url: The requested URL.
:param verify: Whether we should actually verify the certificate.
:param cert: The SSL certificate to verify.

def build_response(self, req, resp):
Builds a :class:`Response &amp;lt;requests.Response&amp;gt;` object from a urllib3
response. <!-- 367d1bc2-8988-4154-91bf-f4cbf2a72923 <=< ACCEPT -->This should not be called from user code, and is only exposed
for use when subclassing the
:class:`HTTPAdapter &amp;lt;requests.adapters.HTTPAdapter&amp;gt;`<!-- ACCEPT >=> 367d1bc2-8988-4154-91bf-f4cbf2a72923 -->

:param req: The :class:`PreparedRequest &amp;lt;PreparedRequest&amp;gt;` used to generate the response.
:param resp: The urllib3 response object.

def get_connection(self, url, proxies=None):
Returns a urllib3 connection for the given URL. <!-- 367d1bc2-8988-4154-91bf-f4cbf2a72923 <=< ACCEPT -->This should not be
called from user code, and is only exposed for use when subclassing the
:class:`HTTPAdapter &amp;lt;requests.adapters.HTTPAdapter&amp;gt;`.<!-- ACCEPT >=> 367d1bc2-8988-4154-91bf-f4cbf2a72923 -->

:param url: The URL to connect to.
:param proxies: (optional) A Requests-style dictionary of proxies used on this request.

def close(self):
Disposes of any internal state.

Currently, this just closes the PoolManager, which closes pooled
connections.

def request_url(self, request, proxies):
Obtain the url to use when making the final request.

If the message is being sent through a HTTP proxy, the full URL has to
be used. Otherwise, we should only use the path portion of the URL.

<!-- 367d1bc2-8988-4154-91bf-f4cbf2a72923 <=< ACCEPT -->This should not be called from user code, and is only exposed for use
when subclassing the
:class:`HTTPAdapter &amp;lt;requests.adapters.HTTPAdapter&amp;gt;`.<!-- ACCEPT >=> 367d1bc2-8988-4154-91bf-f4cbf2a72923 -->

:param request: The :class:`PreparedRequest &amp;lt;PreparedRequest&amp;gt;` being sent.
:param proxies: A dictionary of schemes to proxy URLs.

def add_headers(self, request, **kwargs):
Add any headers needed by the connection. As of v2.0 this does
nothing by default, but is left for overriding by users that subclass
the :class:`HTTPAdapter &amp;lt;requests.adapters.HTTPAdapter&amp;gt;`.

<!-- 367d1bc2-8988-4154-91bf-f4cbf2a72923 <=< ACCEPT -->This should not be called from user code, and is only exposed for use
when subclassing the
:class:`HTTPAdapter &amp;lt;requests.adapters.HTTPAdapter&amp;gt;`.<!-- ACCEPT >=> 367d1bc2-8988-4154-91bf-f4cbf2a72923 -->

:param request: The :class:`PreparedRequest &amp;lt;PreparedRequest&amp;gt;` to add headers to.
:param kwargs: The keyword arguments from the call to send().

def proxy_headers(self, proxy):
Returns a dictionary of the headers to add to any request sent
through a proxy. This works with urllib3 magic to ensure that they are
correctly sent to the proxy, rather than in a tunnelled request if
CONNECT is being used.

<!-- 367d1bc2-8988-4154-91bf-f4cbf2a72923 <=< ACCEPT -->This should not be called from user code, and is only exposed for use
when subclassing the
:class:`HTTPAdapter &amp;lt;requests.adapters.HTTPAdapter&amp;gt;`.<!-- ACCEPT >=> 367d1bc2-8988-4154-91bf-f4cbf2a72923 -->

:param proxies: The url of the proxy being used for this request.
:param kwargs: Optional additional keyword arguments.

requests.api
~~~~~~~~~~~~

This module implements the Requests API.

:copyright: (c) 2012 by Kenneth Reitz.
:license: Apache2, see LICENSE for more details.

def request(method, url, **kwargs):
Constructs and sends a :class:`Request &amp;lt;Request&amp;gt;`.
Returns :class:`Response &amp;lt;Response&amp;gt;` object.

<!-- ccaca5c7-c16d-4069-bdba-511db1a95fa8 <=< ACCEPT -->:param method: method for the new :class:`Request` object.
:param url: URL for the new :class:`Request` object.
:param params: (optional) Dictionary or bytes to be sent in the query string for the :class:`Request`.
:param data: (optional) Dictionary, bytes, or file-like object to send in the body of the :class:`Request`.
:param json: (optional) json data to send in the body of the :class:`Request`.
:param headers: (optional) Dictionary of HTTP Headers to send with the :class:`Request`.
:param cookies: (optional) Dict or CookieJar object to send with the :class:`Request`.
:param files: (optional) Dictionary of ``'name': file-like-objects`` (or ``{'name': ('filename', fileobj)}``) for multipart encoding upload.
:param auth: (optional) Auth tuple to enable Basic/Digest/Custom HTTP Auth.
:param timeout: (optional) How long to wait for the server to send data
before giving up, as a float, or a (`connect timeout, read timeout
&amp;lt;user/advanced.html#timeouts&amp;gt;`_) tuple.
:type timeout: float or tuple
:param allow_redirects: (optional) Boolean. Set to True if POST/PUT/DELETE redirect following is allowed.
:type allow_redirects: bool
:param proxies: (optional) Dictionary mapping protocol to the URL of the proxy.
:param verify: (optional) if ``True``, the SSL cert will be verified. A CA_BUNDLE path can also be provided.
:param stream: (optional) if ``False``, the response content will be immediately downloaded.<!-- ACCEPT >=> ccaca5c7-c16d-4069-bdba-511db1a95fa8 -->
:param cert: (optional) if String, path to ssl client cert file (.pem). If Tuple, ('cert', 'key') pair.

<!-- bba91b68-7842-4c91-a085-082f2f36bf17 <=< ACCEPT -->Usage::

&amp;gt;&amp;gt;&amp;gt; import requests
&amp;gt;&amp;gt;&amp;gt; req = requests.request('GET', 'http://httpbin.org/get')<!-- ACCEPT >=> bba91b68-7842-4c91-a085-082f2f36bf17 -->
&amp;lt;Response [200]&amp;gt;

<!-- a7eee1d9-105a-4e08-8c54-2fa1bb5e2908 <=< ACCEPT -->def get(url, **kwargs):
Sends a GET request. Returns :class:`Response` object.

:param url: URL for the new :class:`Request` object.
:param \*\*kwargs: Optional arguments that ``request`` takes.

def options(url, **kwargs):
Sends a OPTIONS request. Returns :class:`Response` object.

:param url: URL for the new :class:`Request` object.
:param \*\*kwargs: Optional arguments that ``request`` takes.

def head(url, **kwargs):
Sends a HEAD request. Returns :class:`Response` object.

:param url: URL for the new :class:`Request` object.
:param \*\*kwargs: Optional arguments that ``request`` takes.

def post(url, data=None, json=None, **kwargs):
Sends a POST request. Returns :class:`Response` object.

:param url: URL for the new :class:`Request` object.
:param data: (optional) Dictionary, bytes, or file-like object to send in the body of the :class:`Request`.
:param json: (optional) json data to send in the body of the :class:`Request`.
:param \*\*kwargs: Optional arguments that ``request`` takes.

def put(url, data=None, **kwargs):
Sends a PUT request. Returns :class:`Response` object.

:param url: URL for the new :class:`Request` object.
:param data: (optional) Dictionary, bytes, or file-like object to send in the body of the :class:`Request`.
:param \*\*kwargs: Optional arguments that ``request`` takes.

def patch(url, data=None, **kwargs):
Sends a PATCH request. Returns :class:`Response` object.

:param url: URL for the new :class:`Request` object.
:param data: (optional) Dictionary, bytes, or file-like object to send in the body of the :class:`Request`.
:param \*\*kwargs: Optional arguments that ``request`` takes.

def delete(url, **kwargs):
Sends a DELETE request. Returns :class:`Response` object.

:param url: URL for the new :class:`Request` object.
:param \*\*kwargs: Optional arguments that ``request`` takes.<!-- ACCEPT >=> a7eee1d9-105a-4e08-8c54-2fa1bb5e2908 -->

requests.auth
~~~~~~~~~~~~~

This module contains the authentication handlers for Requests.

class AuthBase(object):
Base class that all auth implementations derive from

class HTTPBasicAuth(AuthBase):
Attaches HTTP Basic Authentication to the given Request object.

class HTTPProxyAuth(HTTPBasicAuth):
Attaches HTTP Proxy Authentication to a given Request object.

def handle_redirect(self, r, **kwargs):
Reset num_401_calls counter on redirects.

def handle_401(self, r, **kwargs):
Takes the given response and tries digest-auth, if needed.

certs.py
~~~~~~~~

This module returns the preferred default CA certificate bundle.

If you are packaging Requests, e.g., for a Linux distribution or a managed
environment, you can change the definition of where() to return a separately
packaged CA bundle.

def where():
Return the preferred certificate bundle.

class MockRequest(object):
Wraps a `requests.Request` to mimic a `urllib2.Request`.

The code in `cookielib.CookieJar` expects this interface in order to correctly
manage cookie policies, i.e., determine whether a cookie can be set, given the
domains of the request and the cookie.

The original request object is read-only. The client is responsible for collecting
the new headers via `get_new_headers()` and interpreting them appropriately. You
probably want `get_cookie_header`, defined below.

def add_header(self, key, val):
cookielib has no legitimate use for this method; add it back if you find one.

class MockResponse(object):
Wraps a `httplib.HTTPMessage` to mimic a `urllib.addinfourl`.

...what? Basically, expose the parsed HTTP headers from the server response
the way `cookielib` expects to see them.

def __init__(self, headers):
Make a MockResponse for `cookielib` to read.

:param headers: a httplib.HTTPMessage or analogous carrying the headers

def extract_cookies_to_jar(jar, request, response):
Extract the cookies from the response into a CookieJar.

:param jar: cookielib.CookieJar (not necessarily a RequestsCookieJar)
:param request: our own requests.Request object
:param response: urllib3.HTTPResponse object

def get_cookie_header(jar, request):
Produce an appropriate Cookie header string to be sent with `request`, or None.

def remove_cookie_by_name(cookiejar, name, domain=None, path=None):
Unsets a cookie by name, by default over all domains and paths.

Wraps CookieJar.clear(), is O(n).

class CookieConflictError(RuntimeError):
There are two cookies that meet the criteria specified in the cookie jar.
Use .get and .set and include domain and path args in order to be more specific.

class RequestsCookieJar(cookielib.CookieJar, collections.MutableMapping):
Compatibility class; is a cookielib.CookieJar, but exposes a dict interface.

This is the CookieJar we create by default for requests and sessions that
don't specify one, since some clients may expect response.cookies and
session.cookies to support dict operations.

Don't use the dict interface internally; it's just for compatibility with
with external client code. All `requests` code should work out of the box
with externally provided instances of CookieJar, e.g., LWPCookieJar and
FileCookieJar.

Caution: dictionary operations that are normally O(1) may be O(n).

<!-- 0fb90da6-fdf2-4cf0-b872-fb0682640196 <=< ACCEPT -->Unlike a regular CookieJar, this class is pickleable.<!-- ACCEPT >=> 0fb90da6-fdf2-4cf0-b872-fb0682640196 -->

<!-- d2d1b740-ec55-4639-b80b-bb83e242e87d <=< ACCEPT -->def get(self, name, default=None, domain=None, path=None):
Dict-like get() that also supports optional domain and path args in
order to resolve naming collisions from using one cookie jar over
multiple domains. Caution: operation is O(n), not O(1).<!-- ACCEPT >=> d2d1b740-ec55-4639-b80b-bb83e242e87d -->

<!-- d2d1b740-ec55-4639-b80b-bb83e242e87d <=< ACCEPT -->def set(self, name, value, **kwargs):
Dict-like set() that also supports optional domain and path args in
order to resolve naming collisions from using one cookie jar over
multiple domains.
<!-- ACCEPT >=> d2d1b740-ec55-4639-b80b-bb83e242e87d -->
def iterkeys(self):
Dict-like iterkeys() that returns an iterator of names of cookies from the jar.
See itervalues() and iteritems().

def keys(self):
Dict-like keys() that returns a list of names of cookies from the jar.
See values() and items().

def itervalues(self):
Dict-like itervalues() that returns an iterator of values of cookies from the jar.
See iterkeys() and iteritems().

def values(self):
Dict-like values() that returns a list of values of cookies from the jar.
See keys() and items().

def iteritems(self):
Dict-like iteritems() that returns an iterator of name-value tuples from the jar.
See iterkeys() and itervalues().

def items(self):
Dict-like items() that returns a list of name-value tuples from the jar.
See keys() and values(). Allows client-code to call "dict(RequestsCookieJar)
and get a vanilla python dict of key value pairs.

def list_domains(self):
Utility method to list all the domains in the jar.

def list_paths(self):
Utility method to list all the paths in the jar.

def multiple_domains(self):
Returns True if there are multiple domains in the jar.
Returns False otherwise.

def get_dict(self, domain=None, path=None):
Takes as an argument an optional domain and path and returns a plain old
Python dict of name-value pairs of cookies that meet the requirements.

<!-- 0ec8ec4c-76d6-4b2a-9444-be61541835bf <=< ACCEPT -->def __getitem__(self, name):
Dict-like __getitem__() for compatibility with client code. Throws exception
if there are more than one cookie with name. In that case, use the more
explicit get() method instead. Caution: operation is O(n), not O(1).<!-- ACCEPT >=> 0ec8ec4c-76d6-4b2a-9444-be61541835bf -->

<!-- 0ec8ec4c-76d6-4b2a-9444-be61541835bf <=< ACCEPT -->def __setitem__(self, name, value):
Dict-like __setitem__ for compatibility with client code. Throws exception
if there is already a cookie of that name in the jar. In that case, use the more
explicit set() method instead.<!-- ACCEPT >=> 0ec8ec4c-76d6-4b2a-9444-be61541835bf -->

def __delitem__(self, name):
Deletes a cookie given a name. Wraps cookielib.CookieJar's remove_cookie_by_name().

def update(self, other):
Updates this jar with cookies from another CookieJar or dict-like

def __getstate__(self):
<!-- 0fb90da6-fdf2-4cf0-b872-fb0682640196 <=< ACCEPT -->Unlike a normal CookieJar, this class is pickleable.<!-- ACCEPT >=> 0fb90da6-fdf2-4cf0-b872-fb0682640196 -->

def __setstate__(self, state):
<!-- 0fb90da6-fdf2-4cf0-b872-fb0682640196 <=< ACCEPT -->Unlike a normal CookieJar, this class is pickleable.<!-- ACCEPT >=> 0fb90da6-fdf2-4cf0-b872-fb0682640196 -->

def copy(self):
Return a copy of this RequestsCookieJar.

def create_cookie(name, value, **kwargs):
Make a cookie from underspecified parameters.

By default, the pair of `name` and `value` will be set for the domain ''
and sent on every request (this is sometimes called a "supercookie").

def morsel_to_cookie(morsel):
Convert a Morsel object into a Cookie containing the one k/v pair.

def cookiejar_from_dict(cookie_dict, cookiejar=None, overwrite=True):
Returns a CookieJar from a key/value dictionary.

:param cookie_dict: Dict of key/values to insert into CookieJar.
:param cookiejar: (optional) A cookiejar to add the cookies to.
:param overwrite: (optional) If False, will not replace cookies
already in the jar with new ones.

def merge_cookies(cookiejar, cookies):
Add cookies to cookiejar and returns a merged CookieJar.

:param cookiejar: CookieJar object to add the cookies to.
:param cookies: Dictionary or CookieJar object to be added.

requests.exceptions
~~~~~~~~~~~~~~~~~~~

This module contains the set of Requests' exceptions.

class RequestException(IOError):
There was an ambiguous exception that occurred while handling your
request.

def __init__(self, *args, **kwargs):

Initialize RequestException with `request` and `response` objects.

class HTTPError(RequestException):
An HTTP error occurred.

class ConnectionError(RequestException):
A Connection error occurred.

class ProxyError(ConnectionError):
A proxy error occurred.

class SSLError(ConnectionError):
An SSL error occurred.

class Timeout(RequestException):
The request timed out.

Catching this error will catch both
:exc:`~requests.exceptions.ConnectTimeout` and
:exc:`~requests.exceptions.ReadTimeout` errors.

class ConnectTimeout(ConnectionError, Timeout):
The request timed out while trying to connect to the remote server.

Requests that produced this error are safe to retry.

class ReadTimeout(Timeout):
The server did not send any data in the allotted amount of time.

class URLRequired(RequestException):
A valid URL is required to make a request.

class TooManyRedirects(RequestException):
Too many redirects.

class MissingSchema(RequestException, ValueError):
The URL schema (e.g. http or https) is missing.

class InvalidSchema(RequestException, ValueError):
See defaults.py for valid schemas.

class InvalidURL(RequestException, ValueError):
The URL provided was somehow invalid. 

class ChunkedEncodingError(RequestException):
The server declared chunked encoding but sent an invalid chunk.

class ContentDecodingError(RequestException, BaseHTTPError):
Failed to decode response content

class StreamConsumedError(RequestException, TypeError):
The content for this response was already consumed

class RetryError(RequestException):
Custom retries logic failed

requests.hooks
~~~~~~~~~~~~~~

This module provides the capabilities for the Requests hooks system.

Available hooks:

``response``:
The response generated from a Request.

def dispatch_hook(key, hooks, hook_data, **kwargs):
Dispatches a hook dictionary on a given piece of data.

requests.models
~~~~~~~~~~~~~~~

This module contains the primary objects that power Requests.

class RequestHooksMixin(object):
def register_hook(self, event, hook):
Properly register a hook.

def deregister_hook(self, event, hook):
Deregister a previously registered hook.
Returns True if the hook existed, False if not.

class Request(RequestHooksMixin):
A user-created :class:`Request &amp;lt;Request&amp;gt;` object.

Used to prepare a :class:`PreparedRequest &amp;lt;PreparedRequest&amp;gt;`, which is sent to the server.

:param method: HTTP method to use.
:param url: URL to send.
:param headers: dictionary of headers to send.
:param files: dictionary of {filename: fileobject} files to multipart upload.
:param data: the body to attach to the request. If a dictionary is provided, form-encoding will take place.
:param json: json for the body to attach to the request (if data is not specified).
:param params: dictionary of URL parameters to append to the URL.
:param auth: Auth handler or (user, pass) tuple.
:param cookies: dictionary or CookieJar of cookies to attach to this request.
:param hooks: dictionary of callback hooks, for internal usage.

<!-- bba91b68-7842-4c91-a085-082f2f36bf17 <=< ACCEPT -->Usage::

&amp;gt;&amp;gt;&amp;gt; import requests
&amp;gt;&amp;gt;&amp;gt; req = requests.Request('GET', 'http://httpbin.org/get')<!-- ACCEPT >=> bba91b68-7842-4c91-a085-082f2f36bf17 -->
&amp;gt;&amp;gt;&amp;gt; req.prepare()
&amp;lt;PreparedRequest [GET]&amp;gt;

class PreparedRequest(RequestEncodingMixin, RequestHooksMixin):
The fully mutable :class:`PreparedRequest &amp;lt;PreparedRequest&amp;gt;` object,
containing the exact bytes that will be sent to the server.

Generated from either a :class:`Request &amp;lt;Request&amp;gt;` object or manually.

<!-- bba91b68-7842-4c91-a085-082f2f36bf17 <=< ACCEPT -->Usage::

&amp;gt;&amp;gt;&amp;gt; import requests
&amp;gt;&amp;gt;&amp;gt; req = requests.Request('GET', 'http://httpbin.org/get')<!-- ACCEPT >=> bba91b68-7842-4c91-a085-082f2f36bf17 -->
&amp;gt;&amp;gt;&amp;gt; r = req.prepare()
&amp;lt;PreparedRequest [GET]&amp;gt;

&amp;gt;&amp;gt;&amp;gt; s = requests.Session()
&amp;gt;&amp;gt;&amp;gt; s.send(r)
&amp;lt;Response [200]&amp;gt;

def prepare(self, method=None, url=None, headers=None, files=None,
data=None, params=None, auth=None, cookies=None, hooks=None,
json=None):
Prepares the entire request with the given parameters.

def prepare_method(self, method):
Prepares the given HTTP method.

def prepare_url(self, url, params):
Prepares the given HTTP URL.

def prepare_auth(self, auth, url=''):
Prepares the given HTTP auth data.

class Response(object):
The :class:`Response &amp;lt;Response&amp;gt;` object, which contains a
server's response to an HTTP request.

def __bool__(self):
Returns true if :attr:`status_code` is 'OK'.

def __nonzero__(self):
Returns true if :attr:`status_code` is 'OK'.

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

def is_redirect(self):
True if this Response is a well-formed HTTP redirect that could have
been processed automatically (by :meth:`Session.resolve_redirects`).

def is_permanent_redirect(self):
True if this Response one of the permanant versions of redirect

def apparent_encoding(self):
The apparent encoding, provided by the chardet library

def iter_content(self, chunk_size=1, decode_unicode=False):
<!-- 02fcbfd1-32db-4605-930d-4d49b5f8a7b6 <=< ACCEPT -->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.<!-- ACCEPT >=> 02fcbfd1-32db-4605-930d-4d49b5f8a7b6 -->  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.

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=None, delimiter=None):
<!-- 02fcbfd1-32db-4605-930d-4d49b5f8a7b6 <=< ACCEPT -->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.<!-- ACCEPT >=> 02fcbfd1-32db-4605-930d-4d49b5f8a7b6 -->

def content(self):
Content of the response, in bytes.

def text(self):
Content of the response, in unicode.

If Response.encoding is None, encoding will be guessed using
``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.

def json(self, **kwargs):
Returns the json-encoded content of a response, if any.

:param \*\*kwargs: Optional arguments that ``json.loads`` takes.

def links(self):
Returns the parsed header links of the response, if any.

def raise_for_status(self):
Raises stored :class:`HTTPError`, if one occurred.

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.*

requests.session
~~~~~~~~~~~~~~~~

This module provides a Session object to manage and persist settings across
requests (cookies, auth, proxies).

def merge_setting(request_setting, session_setting, dict_class=OrderedDict):

Determines appropriate setting for a given request, taking into account the
explicit setting on that request, and the setting in the session. If a
setting is a dictionary, they will be merged together using `dict_class`

def merge_hooks(request_hooks, session_hooks, dict_class=OrderedDict):

Properly merges both requests and session hooks.

This is necessary because when request_hooks == {'response': []}, the
merge breaks Session hooks entirely.

class SessionRedirectMixin(object):
def resolve_redirects(self, resp, req, stream=False, timeout=None,
verify=True, cert=None, proxies=None):
Receives a Response. Returns a generator of Responses.

def rebuild_auth(self, prepared_request, response):

When being redirected we may want to strip authentication from the
request to avoid leaking credentials. This method intelligently removes
and reapplies authentication where possible to avoid credential loss.

def rebuild_proxies(self, prepared_request, proxies):

This method re-evaluates the proxy configuration by considering the
environment variables. If we are redirected to a URL covered by
NO_PROXY, we strip the proxy configuration. Otherwise, we set missing
proxy keys for this URL (in case they were stripped by a previous
redirect).

This method also replaces the Proxy-Authorization header where
necessary.

class Session(SessionRedirectMixin):
A Requests session.

Provides cookie persistence, connection-pooling, and configuration.

Basic Usage::

&amp;gt;&amp;gt;&amp;gt; import requests
&amp;gt;&amp;gt;&amp;gt; s = requests.Session()
&amp;gt;&amp;gt;&amp;gt; s.get('http://httpbin.org/get')
200

def request(self, method, url,
params=None,
data=None,
headers=None,
cookies=None,
files=None,
auth=None,
timeout=None,
allow_redirects=True,
proxies=None,
hooks=None,
stream=None,
verify=None,
cert=None,
json=None):
Constructs a :class:`Request &amp;lt;Request&amp;gt;`, prepares it and sends it.
Returns :class:`Response &amp;lt;Response&amp;gt;` object.

<!-- ccaca5c7-c16d-4069-bdba-511db1a95fa8 <=< ACCEPT -->:param method: method for the new :class:`Request` object.
:param url: URL for the new :class:`Request` object.
:param params: (optional) Dictionary or bytes to be sent in the query
string for the :class:`Request`.
:param data: (optional) Dictionary or bytes to send in the body of the
:class:`Request`.
:param json: (optional) json to send in the body of the
:class:`Request`.
:param headers: (optional) Dictionary of HTTP Headers to send with the
:class:`Request`.
:param cookies: (optional) Dict or CookieJar object to send with the
:class:`Request`.
:param files: (optional) Dictionary of ``'filename': file-like-objects``
for multipart encoding upload.
:param auth: (optional) Auth tuple or callable to enable
Basic/Digest/Custom HTTP Auth.
:param timeout: (optional) How long to wait for the server to send
data before giving up, as a float, or a (`connect timeout, read
timeout &amp;lt;user/advanced.html#timeouts&amp;gt;`_) tuple.
:type timeout: float or tuple
:param allow_redirects: (optional) Set to True by default.
:type allow_redirects: bool
:param proxies: (optional) Dictionary mapping protocol to the URL of
the proxy.
:param stream: (optional) whether to immediately download the response
content. Defaults to ``False``.<!-- ACCEPT >=> ccaca5c7-c16d-4069-bdba-511db1a95fa8 -->
:param verify: (optional) if ``True``, the SSL cert will be verified.
A CA_BUNDLE path can also be provided.
:param cert: (optional) if String, path to ssl client cert file (.pem).
If Tuple, ('cert', 'key') pair.

<!-- a7eee1d9-105a-4e08-8c54-2fa1bb5e2908 <=< ACCEPT -->def get(self, url, **kwargs):
Sends a GET request. Returns :class:`Response` object.

:param url: URL for the new :class:`Request` object.
:param \*\*kwargs: Optional arguments that ``request`` takes.

def options(self, url, **kwargs):
Sends a OPTIONS request. Returns :class:`Response` object.

:param url: URL for the new :class:`Request` object.
:param \*\*kwargs: Optional arguments that ``request`` takes.

def head(self, url, **kwargs):
Sends a HEAD request. Returns :class:`Response` object.

:param url: URL for the new :class:`Request` object.
:param \*\*kwargs: Optional arguments that ``request`` takes.

def post(self, url, data=None, json=None, **kwargs):
Sends a POST request. Returns :class:`Response` object.

:param url: URL for the new :class:`Request` object.
:param data: (optional) Dictionary, bytes, or file-like object to send in the body of the :class:`Request`.
:param json: (optional) json to send in the body of the :class:`Request`.
:param \*\*kwargs: Optional arguments that ``request`` takes.

def put(self, url, data=None, **kwargs):
Sends a PUT request. Returns :class:`Response` object.

:param url: URL for the new :class:`Request` object.
:param data: (optional) Dictionary, bytes, or file-like object to send in the body of the :class:`Request`.
:param \*\*kwargs: Optional arguments that ``request`` takes.

def patch(self, url, data=None, **kwargs):
Sends a PATCH request. Returns :class:`Response` object.

:param url: URL for the new :class:`Request` object.
:param data: (optional) Dictionary, bytes, or file-like object to send in the body of the :class:`Request`.
:param \*\*kwargs: Optional arguments that ``request`` takes.

def delete(self, url, **kwargs):
Sends a DELETE request. Returns :class:`Response` object.

:param url: URL for the new :class:`Request` object.
:param \*\*kwargs: Optional arguments that ``request`` takes.<!-- ACCEPT >=> a7eee1d9-105a-4e08-8c54-2fa1bb5e2908 -->

def send(self, request, **kwargs):
Send a given PreparedRequest.

def merge_environment_settings(self, url, proxies, stream, verify, cert):
Check the environment and merge it with some settings.

def close(self):
Closes all adapters and as such the session

def mount(self, prefix, adapter):
Registers a connection adapter to a prefix.

Adapters are sorted in descending order by key length.

def session():
Returns a :class:`Session` for context-management.

requests.structures
~~~~~~~~~~~~~~~~~~~

Data structures that power Requests.

class CaseInsensitiveDict(collections.MutableMapping):

A case-insensitive ``dict``-like object.

Implements all methods and operations of
``collections.MutableMapping`` as well as dict's ``copy``. Also
provides ``lower_items``.

All keys are expected to be strings. The structure remembers the
case of the last key to be set, and ``iter(instance)``,
``keys()``, ``items()``, ``iterkeys()``, and ``iteritems()``
will contain case-sensitive keys. However, querying and contains
testing is case insensitive::

cid = CaseInsensitiveDict()
cid['Accept'] = 'application/json'
cid['aCCEPT'] == 'application/json'  # True
list(cid) == ['Accept']  # True

For example, ``headers['content-encoding']`` will return the
value of a ``'Content-Encoding'`` response header, regardless
of how the header name was originally stored.

If the constructor, ``.update``, or equality comparison
operations are given keys that have equal ``.lower()``s, the
behavior is undefined.

def lower_items(self):
Like iteritems(), but with all lowercase keys.

class LookupDict(dict):
Dictionary lookup object.

requests.utils
~~~~~~~~~~~~~~

This module provides utility functions that are used within Requests
that are also useful for external consumption.

def dict_to_sequence(d):
Returns an internal sequence dictionary update.

def get_netrc_auth(url):
Returns the Requests tuple auth for a given url from netrc.

def guess_filename(obj):
Tries to guess the filename of the given object.

def from_key_val_list(value):
Take an object and test to see if it can be represented as a
dictionary. Unless it can not be represented as such, return an
OrderedDict, e.g.,

::

&amp;gt;&amp;gt;&amp;gt; from_key_val_list([('key', 'val')])
OrderedDict([('key', 'val')])
&amp;gt;&amp;gt;&amp;gt; from_key_val_list('string')
ValueError: need more than 1 value to unpack
&amp;gt;&amp;gt;&amp;gt; from_key_val_list({'key': 'val'})
OrderedDict([('key', 'val')])

def to_key_val_list(value):
Take an object and test to see if it can be represented as a
dictionary. If it can be, return a list of tuples, e.g.,

::

&amp;gt;&amp;gt;&amp;gt; to_key_val_list([('key', 'val')])
[('key', 'val')]
&amp;gt;&amp;gt;&amp;gt; to_key_val_list({'key': 'val'})
[('key', 'val')]
&amp;gt;&amp;gt;&amp;gt; to_key_val_list('string')
ValueError: cannot encode objects that are not 2-tuples.

def parse_list_header(value):
Parse lists as described by RFC 2068 Section 2.

In particular, parse comma-separated lists where the elements of
the list may include quoted-strings.  A quoted-string could
contain a comma.  A non-quoted string could have quotes in the
middle.  Quotes are removed automatically after parsing.

It basically works like :func:`parse_set_header` just that items
may appear multiple times and case sensitivity is preserved.

The return value is a standard :class:`list`:

&amp;gt;&amp;gt;&amp;gt; parse_list_header('token, "quoted value"')
['token', 'quoted value']

<!-- 6eb8af5f-ffe3-4f16-ad98-428a0f5ca957 <=< ACCEPT -->To create a header from the :class:`list` again, use the
:func:`dump_header` function.

:param value: a string with a list header.
:return: :class:`list`
<!-- ACCEPT >=> 6eb8af5f-ffe3-4f16-ad98-428a0f5ca957 -->
def parse_dict_header(value):
Parse lists of key, value pairs as described by RFC 2068 Section 2 and
convert them into a python dict:

&amp;gt;&amp;gt;&amp;gt; d = parse_dict_header('foo="is a fish", bar="as well"')
&amp;gt;&amp;gt;&amp;gt; type(d) is dict
True
&amp;gt;&amp;gt;&amp;gt; sorted(d.items())
[('bar', 'as well'), ('foo', 'is a fish')]

If there is no value for a key it will be `None`:

&amp;gt;&amp;gt;&amp;gt; parse_dict_header('key_without_value')
{'key_without_value': None}

<!-- 6eb8af5f-ffe3-4f16-ad98-428a0f5ca957 <=< ACCEPT -->To create a header from the :class:`dict` again, use the
:func:`dump_header` function.

:param value: a string with a dict header.
:return: :class:`dict`<!-- ACCEPT >=> 6eb8af5f-ffe3-4f16-ad98-428a0f5ca957 -->

def unquote_header_value(value, is_filename=False):
rUnquotes a header value.  (Reversal of :func:`quote_header_value`).
This does not use the real unquoting but what browsers are actually
using for quoting.

:param value: the header value to unquote.

def dict_from_cookiejar(cj):
Returns a key/value dictionary from a CookieJar.

:param cj: CookieJar object to extract cookies from.

def add_dict_to_cookiejar(cj, cookie_dict):
Returns a CookieJar from a key/value dictionary.

:param cj: CookieJar to insert cookies into.
:param cookie_dict: Dict of key/values to insert into CookieJar.

def get_encodings_from_content(content):
Returns encodings from given content string.

:param content: bytestring to extract encodings from.

def get_encoding_from_headers(headers):
Returns encodings from given HTTP Header Dict.

:param headers: dictionary to extract encoding from.

def stream_decode_response_unicode(iterator, r):
Stream decodes a iterator.

def iter_slices(string, slice_length):
Iterate over slices of a string.

def get_unicode_from_response(r):
Returns the requested content back in unicode.

:param r: Response object to get unicode content from.

Tried:

1. charset from content-type
2. fall back and replace all unicode characters

def unquote_unreserved(uri):
Un-escape any percent-escape sequences in a URI that are unreserved
characters. This leaves all reserved, illegal and non-ASCII bytes encoded.

def requote_uri(uri):
Re-quote the given URI.

This function passes the given URI through an unquote/quote cycle to
ensure that it is fully and consistently quoted.

def address_in_network(ip, net):

This function allows you to check if on IP belongs to a network subnet
Example: returns True if ip = 192.168.1.1 and net = 192.168.1.0/24
returns False if ip = 192.168.1.1 and net = 192.168.100.0/24

def dotted_netmask(mask):

Converts mask from /xx format to xxx.xxx.xxx.xxx
Example: if mask is 24 function returns 255.255.255.0

def is_valid_cidr(string_network):
Very simple check of the cidr format in no_proxy variable

def should_bypass_proxies(url):

Returns whether we should bypass proxies or not.

def get_environ_proxies(url):
Return a dict of environment proxies.

def default_user_agent(name="python-requests"):
Return a string representing the default user agent.

def parse_header_links(value):
Return a dict of parsed link headers proxies.

i.e. Link: &amp;lt;http:/.../front.jpeg&amp;gt;; rel=front; type="image/jpeg",&amp;lt;http://.../back.jpeg&amp;gt;; rel=back;type="image/jpeg"

def prepend_scheme_if_needed(url, new_scheme):
Given a URL that may or may not have a scheme, prepend the given scheme.
Does not replace a present scheme with the one provided as an argument.

def get_auth_from_url(url):
Given a url with authentication components, extract them into a tuple of
username,password.

def to_native_string(string, encoding='ascii'):

Given a string object, regardless of type, returns a representation of that
string in the native string type, encoding and decoding where necessary.
This assumes ASCII unless told otherwise.

def urldefragauth(url):

Given a url remove the fragment and the authentication part


</plainxml>