This module provides a Session object to manage and persist settings across requests (cookies, auth, proxies).
Bases: cloudfusion.third_party.requests_1_2_3.requests.sessions.SessionRedirectMixin
A Requests session.
Provides cookie persistience, connection-pooling, and configuration.
Basic Usage:
>>> import requests
>>> s = requests.Session()
>>> s.get('http://httpbin.org/get')
200
Default Authentication tuple or object to attach to Request.
SSL certificate default.
Closes all adapters and as such the session
Sends a DELETE request. Returns Response object.
Parameters: |
|
---|
Sends a GET request. Returns Response object.
Parameters: |
|
---|
Returns the appropriate connnection adapter for the given URL.
Sends a HEAD request. Returns Response object.
Parameters: |
|
---|
A case-insensitive dictionary of headers to be sent on each Request sent from this Session.
Event-handling hooks.
Maximum number of redirects allowed. If the request exceeds this limit, a TooManyRedirects exception is raised.
Registers a connection adapter to a prefix.
Adapters are sorted in descending order by key length.
Sends a OPTIONS request. Returns Response object.
Parameters: |
|
---|
Dictionary of querystring data to attach to each Request. The dictionary values may be lists for representing multivalued query parameters.
Sends a PATCH request. Returns Response object.
Parameters: |
|
---|
Sends a POST request. Returns Response object.
Parameters: |
|
---|
Dictionary mapping protocol to the URL of the proxy (e.g. {‘http’: ‘foo.bar:3128’}) to be used on each Request.
Sends a PUT request. Returns Response object.
Parameters: |
|
---|
Constructs a Request, prepares it and sends it. Returns Response object.
Parameters: |
|
---|
Send a given PreparedRequest.
Stream response content default.
Should we trust the environment?
SSL Verification default.
Bases: object
Receives a Response. Returns a generator of Responses.
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
This module contains the transport adapters that Requests uses to define and maintain connections.
Bases: object
The Base Transport Adapter
Bases: cloudfusion.third_party.requests_1_2_3.requests.adapters.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 Session class under the covers.
Parameters: |
|
---|
Usage:
>>> import requests
>>> s = requests.Session()
>>> a = requests.adapters.HTTPAdapter()
>>> s.mount('http://', a)
Add any headers needed by the connection. Currently this adds a Proxy-Authorization header.
This should not be called from user code, and is only exposed for use when subclassing the HTTPAdapter.
Parameters: |
|
---|
Builds a Response object from a urllib3 response. This should not be called from user code, and is only exposed for use when subclassing the HTTPAdapter
Parameters: |
|
---|
Verify a SSL certificate. This method should not be called from user code, and is only exposed for use when subclassing the HTTPAdapter.
Parameters: |
|
---|
Disposes of any internal state.
Currently, this just closes the PoolManager, which closes pooled connections.
Returns a urllib3 connection for the given URL. This should not be called from user code, and is only exposed for use when subclassing the HTTPAdapter.
Parameters: |
|
---|
Initializes a urllib3 PoolManager. This method should not be called from user code, and is only exposed for use when subclassing the HTTPAdapter.
Parameters: |
|
---|
Obtain the url to use when making the final request.
If the message is being sent through a proxy, the full URL has to be used. Otherwise, we should only use the path portion of the URL.
This shoudl not be called from user code, and is only exposed for use when subclassing the HTTPAdapter.
Parameters: |
|
---|
Sends PreparedRequest object. Returns Response object.
Parameters: |
|
---|
Compatibility code to be able to use cookielib.CookieJar with requests.
requests.utils imports from here, so be careful with imports.
Bases: exceptions.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.
Bases: 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.
cookielib has no legitimate use for this method; add it back if you find one.
Bases: 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.
Make a MockResponse for cookielib to read.
Parameters: | headers – a httplib.HTTPMessage or analogous carrying the headers |
---|
Bases: cookielib.CookieJar, _abcoll.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).
Unlike a regular CookieJar, this class is pickleable.
Requests uses this method internally to get cookie values. Takes as args name and optional domain and path. Returns a cookie.value. If there are conflicting cookies, _find arbitrarily chooses one. See _find_no_duplicates if you want an exception thrown if there are conflicting cookies.
__get_item__ and get call _find_no_duplicates – never used in Requests internally. Takes as args name and optional domain and path. Returns a cookie.value. Throws KeyError if cookie is not found and CookieConflictError if there are multiple cookies that match name and optionally domain and path.
Return a copy of this RequestsCookieJar.
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).
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.
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.
Dict-like keys() that returns a list of names of cookies from the jar. See values() and items().
Utility method to list all the domains in the jar.
Utility method to list all the paths in the jar.
Returns True if there are multiple domains in the jar. Returns False otherwise.
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.
Updates this jar with cookies from another CookieJar or dict-like
Dict-like values() that returns a list of values of cookies from the jar. See keys() and items().
Returns a CookieJar from a key/value dictionary.
Parameters: | cookie_dict – Dict of key/values to insert into CookieJar. |
---|
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”).
Extract the cookies from the response into a CookieJar.
Parameters: |
|
---|
Produce an appropriate Cookie header string to be sent with request, or None.
Convert a Morsel object into a Cookie containing the one k/v pair.
Unsets a cookie by name, by default over all domains and paths.
Wraps CookieJar.clear(), is O(n).
This module contains the authentication handlers for Requests.
Bases: object
Base class that all auth implementations derive from
Bases: cloudfusion.third_party.requests_1_2_3.requests.auth.AuthBase
Attaches HTTP Basic Authentication to the given Request object.
Bases: cloudfusion.third_party.requests_1_2_3.requests.auth.AuthBase
Attaches HTTP Digest Authentication to the given Request object.
Takes the given response and tries digest-auth, if needed.
Bases: cloudfusion.third_party.requests_1_2_3.requests.auth.HTTPBasicAuth
Attaches HTTP Proxy Authentication to a given Request object.
Returns a Basic Auth string.
This module contains the primary objects that power Requests.
Bases: cloudfusion.third_party.requests_1_2_3.requests.models.RequestEncodingMixin, cloudfusion.third_party.requests_1_2_3.requests.models.RequestHooksMixin
The fully mutable PreparedRequest object, containing the exact bytes that will be sent to the server.
Generated from either a Request object or manually.
Usage:
>>> import requests
>>> req = requests.Request('GET', 'http://httpbin.org/get')
>>> r = req.prepare()
<PreparedRequest [GET]>
>>> s = requests.Session()
>>> s.send(r)
<Response [200]>
request body to send to the server.
dictionary of HTTP headers.
dictionary of callback hooks, for internal usage.
HTTP verb to send to the server.
Prepares the given HTTP auth data.
Prepares the given HTTP body data.
Prepares the given HTTP cookie data.
Prepares the given HTTP headers.
Prepares the given hooks.
Prepares the given HTTP method.
Prepares the given HTTP URL.
HTTP URL to send the request to.
Bases: cloudfusion.third_party.requests_1_2_3.requests.models.RequestHooksMixin
A user-created Request object.
Used to prepare a PreparedRequest, which is sent to the server.
Parameters: |
|
---|
Usage:
>>> import requests
>>> req = requests.Request('GET', 'http://httpbin.org/get')
>>> req.prepare()
<PreparedRequest [GET]>
Constructs a PreparedRequest for transmission and returns it.
Bases: object
Build the body for a multipart/form-data request.
Will successfully encode files when passed as a dict or a list of 2-tuples. Order is retained if data is a list of 2-tuples but abritrary if parameters are supplied as a dict.
Encode parameters in a piece of data.
Will successfully encode parameters when passed as a dict or a list of 2-tuples. Order is retained if data is a list of 2-tuples but arbitrary if parameters are supplied as a dict.
Build the path URL to use.
Bases: object
Deregister a previously registered hook. Returns True if the hook existed, False if not.
Properly register a hook.
Bases: object
The Response object, which contains a server’s response to an HTTP request.
The apparent encoding, provided by the lovely Charade library (Thanks, Ian!).
Content of the response, in bytes.
A CookieJar of Cookies the server sent back.
The amount of time elapsed between sending the request and the arrival of the response (as a timedelta)
Encoding to decode with when accessing r.text.
Case-insensitive Dictionary of Response Headers. For example, headers['content-encoding'] will return the value of a 'Content-Encoding' response header.
A list of Response objects from the history of the Request. Any redirect responses will end up here. The list is sorted from the oldest to the most recent request.
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.
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.
Returns the json-encoded content of a response, if any.
Parameters: | **kwargs – Optional arguments that json.loads takes. |
---|
Returns the parsed header links of the response, if any.
Raises stored HTTPError, if one occurred.
File-like object representation of response (for advanced usage). Requires that ``stream=True` on the request.
Integer Code of responded HTTP Status.
Content of the response, in unicode.
if Response.encoding is None and chardet module is available, encoding will be guessed.
Final URL location of Response.
This module implements the Requests API.
copyright: |
|
---|---|
license: | Apache2, see LICENSE for more details. |
Sends a DELETE request. Returns Response object.
Parameters: |
|
---|
Sends a GET request. Returns Response object.
Parameters: |
|
---|
Sends a HEAD request. Returns Response object.
Parameters: |
|
---|
Sends a OPTIONS request. Returns Response object.
Parameters: |
|
---|
Sends a PATCH request. Returns Response object.
Parameters: |
|
---|
Sends a POST request. Returns Response object.
Parameters: |
|
---|
Sends a PUT request. Returns Response object.
Parameters: |
|
---|
Constructs and sends a Request. Returns Response object.
Parameters: |
|
---|
Usage:
>>> import requests
>>> req = requests.request('GET', 'http://httpbin.org/get')
<Response [200]>
This module provides utility functions that are used within Requests that are also useful for external consumption.
Returns a CookieJar from a key/value dictionary.
Parameters: |
|
---|
Return a string representing the default user agent.
Returns a key/value dictionary from a CookieJar.
Parameters: | cj – CookieJar object to extract cookies from. |
---|
Returns an internal sequence dictionary update.
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.,
>>> from_key_val_list([('key', 'val')])
OrderedDict([('key', 'val')])
>>> from_key_val_list('string')
ValueError: need more than 1 value to unpack
>>> from_key_val_list({'key': 'val'})
OrderedDict([('key', 'val')])
Given a url with authentication components, extract them into a tuple of username,password.
Returns encodings from given HTTP Header Dict.
Parameters: | headers – dictionary to extract encoding from. |
---|
Returns encodings from given content string.
Parameters: | content – bytestring to extract encodings from. |
---|
Return a dict of environment proxies.
Returns the Requests tuple auth for a given url from netrc.
Returns the requested content back in unicode.
Parameters: | r – Response object to get unicode content from. |
---|
Tried:
Tries to guess the filename of the given object.
Iterate over slices of a string.
Parse lists of key, value pairs as described by RFC 2068 Section 2 and convert them into a python dict:
>>> d = parse_dict_header('foo="is a fish", bar="as well"')
>>> type(d) is dict
True
>>> sorted(d.items())
[('bar', 'as well'), ('foo', 'is a fish')]
If there is no value for a key it will be None:
>>> parse_dict_header('key_without_value')
{'key_without_value': None}
To create a header from the dict again, use the dump_header() function.
Parameters: | value – a string with a dict header. |
---|---|
Returns: | dict |
Return a dict of parsed link headers proxies.
i.e. Link: <http:/.../front.jpeg>; rel=front; type=”image/jpeg”,<http://.../back.jpeg>; rel=back;type=”image/jpeg”
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 parse_set_header() just that items may appear multiple times and case sensitivity is preserved.
The return value is a standard list:
>>> parse_list_header('token, "quoted value"')
['token', 'quoted value']
To create a header from the list again, use the dump_header() function.
Parameters: | value – a string with a list header. |
---|---|
Returns: | list |
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.
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.
Stream decodes a iterator.
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.,
>>> to_key_val_list([('key', 'val')])
[('key', 'val')]
>>> to_key_val_list({'key': 'val'})
[('key', 'val')]
>>> to_key_val_list('string')
ValueError: cannot encode objects that are not 2-tuples.
Unquotes a header value. (Reversal of quote_header_value()). This does not use the real unquoting but what browsers are actually using for quoting.
Parameters: | value – the header value to unquote. |
---|
Un-escape any percent-escape sequences in a URI that are unreserved characters. This leaves all reserved, illegal and non-ASCII bytes encoded.
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.
Return the preferred certificate bundle.
This module contains the set of Requests’ exceptions.
Bases: cloudfusion.third_party.requests_1_2_3.requests.exceptions.RequestException
A Connection error occurred.
Bases: cloudfusion.third_party.requests_1_2_3.requests.exceptions.RequestException
An HTTP error occurred.
Initializes HTTPError with optional response object.
Bases: cloudfusion.third_party.requests_1_2_3.requests.exceptions.RequestException, exceptions.ValueError
See defaults.py for valid schemas.
Bases: cloudfusion.third_party.requests_1_2_3.requests.exceptions.RequestException, exceptions.ValueError
The URL provided was somehow invalid.
Bases: cloudfusion.third_party.requests_1_2_3.requests.exceptions.RequestException, exceptions.ValueError
The URL schema (e.g. http or https) is missing.
Bases: exceptions.RuntimeError
There was an ambiguous exception that occurred while handling your request.
Bases: cloudfusion.third_party.requests_1_2_3.requests.exceptions.ConnectionError
An SSL error occurred.
Bases: cloudfusion.third_party.requests_1_2_3.requests.exceptions.RequestException
The request timed out.
Bases: cloudfusion.third_party.requests_1_2_3.requests.exceptions.RequestException
Too many redirects.
Bases: cloudfusion.third_party.requests_1_2_3.requests.exceptions.RequestException
A valid URL is required to make a request.
Data structures that power Requests.
Bases: _abcoll.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.
Like iteritems(), but with all lowercase keys.
This module provides the capabilities for the Requests hooks system.
Available hooks:
Dispatches a hook dictionary on a given piece of data.