class documentation

class Session(SessionRedirectMixin):

View In Hierarchy

A Requests session.

Provides cookie persistence, connection-pooling, and configuration.

Basic Usage:

>>> import requests
>>> s = requests.Session()
>>> s.get('https://httpbin.org/get')
<Response [200]>

Or as a context manager:

>>> with requests.Session() as s:
...     s.get('https://httpbin.org/get')
<Response [200]>
Method __enter__ Undocumented
Method __exit__ Undocumented
Method __getstate__ Undocumented
Method __init__ Undocumented
Method __setstate__ Undocumented
Method close Closes all adapters and as such the session
Method delete Sends a DELETE request. Returns Response object.
Method get Sends a GET request. Returns Response object.
Method get​_adapter Returns the appropriate connection adapter for the given URL.
Method head Sends a HEAD request. Returns Response object.
Method merge​_environment​_settings Check the environment and merge it with some settings.
Method mount Registers a connection adapter to a prefix.
Method options Sends a OPTIONS request. Returns Response object.
Method patch Sends a PATCH request. Returns Response object.
Method post Sends a POST request. Returns Response object.
Method prepare​_request No summary
Method put Sends a PUT request. Returns Response object.
Method request Constructs a Request, prepares it and sends it. Returns Response object.
Method send Send a given PreparedRequest.
Class Variable __attrs__ Undocumented
Instance Variable adapters Undocumented
Instance Variable auth Undocumented
Instance Variable cert Undocumented
Instance Variable cookies Undocumented
Instance Variable headers Undocumented
Instance Variable hooks Undocumented
Instance Variable max​_redirects Undocumented
Instance Variable params Undocumented
Instance Variable proxies Undocumented
Instance Variable stream Undocumented
Instance Variable trust​_env Undocumented
Instance Variable verify Undocumented

Inherited from SessionRedirectMixin:

Method get​_redirect​_target Receives a Response. Returns a redirect URI or None
Method rebuild​_auth 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.
Method rebuild​_method When being redirected we may want to change the method of the request based on certain specs or browser behavior.
Method rebuild​_proxies No summary
Method resolve​_redirects Receives a Response. Returns a generator of Responses or Requests.
Method should​_strip​_auth Decide whether Authorization header should be removed when redirecting
def __enter__(self):

Undocumented

def __exit__(self, *args):

Undocumented

def __getstate__(self):

Undocumented

def __init__(self):

Undocumented

def __setstate__(self, state):

Undocumented

def close(self):
Closes all adapters and as such the session
def delete(self, url, **kwargs):
Sends a DELETE request. Returns Response object.
Parameters
urlURL for the new Request object.
**kwargsOptional arguments that request takes.
Returns
requests.ResponseUndocumented
def get(self, url, **kwargs):
Sends a GET request. Returns Response object.
Parameters
urlURL for the new Request object.
**kwargsOptional arguments that request takes.
Returns
requests.ResponseUndocumented
def get_adapter(self, url):
Returns the appropriate connection adapter for the given URL.
Returns
requests.adapters.BaseAdapterUndocumented
def head(self, url, **kwargs):
Sends a HEAD request. Returns Response object.
Parameters
urlURL for the new Request object.
**kwargsOptional arguments that request takes.
Returns
requests.ResponseUndocumented
def merge_environment_settings(self, url, proxies, stream, verify, cert):
Check the environment and merge it with some settings.
Returns
dictUndocumented
def mount(self, prefix, adapter):

Registers a connection adapter to a prefix.

Adapters are sorted in descending order by prefix length.

def options(self, url, **kwargs):
Sends a OPTIONS request. Returns Response object.
Parameters
urlURL for the new Request object.
**kwargsOptional arguments that request takes.
Returns
requests.ResponseUndocumented
def patch(self, url, data=None, **kwargs):
Sends a PATCH request. Returns Response object.
Parameters
urlURL for the new Request object.
data(optional) Dictionary, list of tuples, bytes, or file-like object to send in the body of the Request.
**kwargsOptional arguments that request takes.
Returns
requests.ResponseUndocumented
def post(self, url, data=None, json=None, **kwargs):
Sends a POST request. Returns Response object.
Parameters
urlURL for the new Request object.
data(optional) Dictionary, list of tuples, bytes, or file-like object to send in the body of the Request.
json(optional) json to send in the body of the Request.
**kwargsOptional arguments that request takes.
Returns
requests.ResponseUndocumented
def prepare_request(self, 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.
Returns
requests.PreparedRequestUndocumented
def put(self, url, data=None, **kwargs):
Sends a PUT request. Returns Response object.
Parameters
urlURL for the new Request object.
data(optional) Dictionary, list of tuples, bytes, or file-like object to send in the body of the Request.
**kwargsOptional arguments that request takes.
Returns
requests.ResponseUndocumented
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 Request, prepares it and sends it. Returns Response object.
Parameters
methodmethod for the new Request object.
urlURL for the new Request object.
params(optional) Dictionary or bytes to be sent in the query string for the Request.
data(optional) Dictionary, list of tuples, bytes, or file-like object 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 :ref:`(connect timeout, read timeout) <timeouts>` tuple.
allow​_redirects:bool(optional) Set to True by default.
proxies(optional) Dictionary mapping protocol or protocol and hostname to the URL of the proxy.
hooksUndocumented
stream(optional) whether to immediately download the response content. Defaults to False.
verify(optional) Either a boolean, in which case it controls whether we verify the server's TLS certificate, or a string, in which case it must be a path to a CA bundle to use. Defaults to True. When set to False, requests will accept any TLS certificate presented by the server, and will ignore hostname mismatches and/or expired certificates, which will make your application vulnerable to man-in-the-middle (MitM) attacks. Setting verify to False may be useful during local development or testing.
cert(optional) if String, path to ssl client cert file (.pem). If Tuple, ('cert', 'key') pair.
json(optional) json to send in the body of the Request.
Returns
requests.ResponseUndocumented
def send(self, request, **kwargs):
Send a given PreparedRequest.
Returns
requests.ResponseUndocumented
__attrs__: list[str] =

Undocumented

adapters =

Undocumented

auth =

Undocumented

cert =

Undocumented

cookies =

Undocumented

headers =

Undocumented

hooks =

Undocumented

max_redirects =

Undocumented

params: dict =

Undocumented

proxies: dict =

Undocumented

stream: bool =

Undocumented

trust_env: bool =

Undocumented

verify: bool =

Undocumented