pytwitch.twitch.Session

class pytwitch.twitch.Session

Bases: requests.sessions.SessionRedirectMixin

A Requests session.

Provides cookie persistence, connection-pooling, and configuration.

Basic Usage:

>>> import requests
>>> s = requests.Session()
>>> s.get('http://httpbin.org/get')
200
__init__()

Methods

__init__()
close() Closes all adapters and as such the session
delete(url, **kwargs) Sends a DELETE request.
get(url, **kwargs) Sends a GET request.
get_adapter(url) Returns the appropriate connnection adapter for the given URL.
head(url, **kwargs) Sends a HEAD request.
merge_environment_settings(url, proxies, ...) Check the environment and merge it with some settings.
mount(prefix, adapter) Registers a connection adapter to a prefix.
options(url, **kwargs) Sends a OPTIONS request.
patch(url[, data]) Sends a PATCH request.
post(url[, data, json]) Sends a POST request.
prepare_request(request) Constructs a PreparedRequest for transmission and returns it.
put(url[, data]) Sends a PUT request.
rebuild_auth(prepared_request, response) When being redirected we may want to strip authentication from the request to avoid leaking credentials.
rebuild_proxies(prepared_request, proxies) This method re-evaluates the proxy configuration by considering the environment variables.
request(method, url[, params, data, ...]) Constructs a Request, prepares it and sends it.
resolve_redirects(resp, req[, stream, ...]) Receives a Response.
send(request, **kwargs) Send a given PreparedRequest.
headers = None

A case-insensitive dictionary of headers to be sent on each Request sent from this Session.

auth = None

Default Authentication tuple or object to attach to Request.

proxies = None

Dictionary mapping protocol to the URL of the proxy (e.g. {‘http’: ‘foo.bar:3128’}) to be used on each Request.

hooks = None

Event-handling hooks.

params = None

Dictionary of querystring data to attach to each Request. The dictionary values may be lists for representing multivalued query parameters.

stream = None

Stream response content default.

verify = None

SSL Verification default.

cert = None

SSL certificate default.

max_redirects = None

Maximum number of redirects allowed. If the request exceeds this limit, a TooManyRedirects exception is raised.

trust_env = None

Should we trust the environment?

cookies = None

A CookieJar containing all currently outstanding cookies set on this session. By default it is a RequestsCookieJar, but may be any other cookielib.CookieJar compatible object.

prepare_request(request)

Constructs a PreparedRequest for transmission and returns it. The PreparedRequest has settings merged from the Request instance and those of the Session.

Parameters:requestRequest instance to prepare with this session’s settings.
request(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 Request, prepares it and sends it. Returns Response object.

Parameters:
  • method – method for the new Request object.
  • url – URL for the new Request object.
  • params – (optional) Dictionary or bytes to be sent in the query string for the Request.
  • data – (optional) Dictionary or bytes to send in the body of the Request.
  • json – (optional) json to send in the body of the Request.
  • headers – (optional) Dictionary of HTTP Headers to send with the Request.
  • cookies – (optional) Dict or CookieJar object to send with the Request.
  • files – (optional) Dictionary of 'filename': file-like-objects for multipart encoding upload.
  • auth – (optional) Auth tuple or callable to enable Basic/Digest/Custom HTTP Auth.
  • timeout (float or tuple) – (optional) How long to wait for the server to send data before giving up, as a float, or a (connect timeout, read timeout) tuple.
  • allow_redirects (bool) – (optional) Set to True by default.
  • proxies – (optional) Dictionary mapping protocol to the URL of the proxy.
  • stream – (optional) whether to immediately download the response content. Defaults to False.
  • verify – (optional) if True, the SSL cert will be verified. A CA_BUNDLE path can also be provided.
  • cert – (optional) if String, path to ssl client cert file (.pem). If Tuple, (‘cert’, ‘key’) pair.
get(url, **kwargs)

Sends a GET request. Returns Response object.

Parameters:
  • url – URL for the new Request object.
  • **kwargs – Optional arguments that request takes.
options(url, **kwargs)

Sends a OPTIONS request. Returns Response object.

Parameters:
  • url – URL for the new Request object.
  • **kwargs – Optional arguments that request takes.
head(url, **kwargs)

Sends a HEAD request. Returns Response object.

Parameters:
  • url – URL for the new Request object.
  • **kwargs – Optional arguments that request takes.
post(url, data=None, json=None, **kwargs)

Sends a POST request. Returns Response object.

Parameters:
  • url – URL for the new Request object.
  • data – (optional) Dictionary, bytes, or file-like object to send in the body of the Request.
  • json – (optional) json to send in the body of the Request.
  • **kwargs – Optional arguments that request takes.
put(url, data=None, **kwargs)

Sends a PUT request. Returns Response object.

Parameters:
  • url – URL for the new Request object.
  • data – (optional) Dictionary, bytes, or file-like object to send in the body of the Request.
  • **kwargs – Optional arguments that request takes.
patch(url, data=None, **kwargs)

Sends a PATCH request. Returns Response object.

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

Sends a DELETE request. Returns Response object.

Parameters:
  • url – URL for the new Request object.
  • **kwargs – Optional arguments that request takes.
send(request, **kwargs)

Send a given PreparedRequest.

merge_environment_settings(url, proxies, stream, verify, cert)

Check the environment and merge it with some settings.

get_adapter(url)

Returns the appropriate connnection adapter for the given URL.

close()

Closes all adapters and as such the session

mount(prefix, adapter)

Registers a connection adapter to a prefix.

Adapters are sorted in descending order by key length.