class Session(SessionRedirectMixin): (source)
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 :class:`Response` object. |
Method | get |
Sends a GET request. Returns :class:`Response` object. |
Method | get |
Returns the appropriate connection adapter for the given URL. |
Method | head |
Sends a HEAD request. Returns :class:`Response` object. |
Method | merge |
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 :class:`Response` object. |
Method | patch |
Sends a PATCH request. Returns :class:`Response` object. |
Method | post |
Sends a POST request. Returns :class:`Response` object. |
Method | prepare |
Constructs a :class:`PreparedRequest <PreparedRequest>` for transmission and returns it. The :class:`PreparedRequest` has settings merged from the :class:`Request <Request>` instance and those of the :class:`Session`. |
Method | put |
Sends a PUT request. Returns :class:`Response` object. |
Method | request |
Constructs a :class:`Request <Request>`, prepares it and sends it. Returns :class:`Response <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 |
Undocumented |
Instance Variable | params |
Undocumented |
Instance Variable | proxies |
Undocumented |
Instance Variable | stream |
Undocumented |
Instance Variable | trust |
Undocumented |
Instance Variable | verify |
Undocumented |
Inherited from SessionRedirectMixin
:
Method | get |
Receives a Response. Returns a redirect URI or ``None`` |
Method | rebuild |
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 |
When being redirected we may want to change the method of the request based on certain specs or browser behavior. |
Method | rebuild |
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). |
Method | resolve |
Receives a Response. Returns a generator of Responses or Requests. |
Method | should |
Decide whether Authorization header should be removed when redirecting |
Sends a DELETE request. Returns :class:`Response` object. :param url: URL for the new :class:`Request` object. :param \*\*kwargs: Optional arguments that ``request`` takes. :rtype: requests.Response
Sends a GET request. Returns :class:`Response` object. :param url: URL for the new :class:`Request` object. :param \*\*kwargs: Optional arguments that ``request`` takes. :rtype: requests.Response
Sends a HEAD request. Returns :class:`Response` object. :param url: URL for the new :class:`Request` object. :param \*\*kwargs: Optional arguments that ``request`` takes. :rtype: requests.Response
Registers a connection adapter to a prefix. Adapters are sorted in descending order by prefix length.
Sends a OPTIONS request. Returns :class:`Response` object. :param url: URL for the new :class:`Request` object. :param \*\*kwargs: Optional arguments that ``request`` takes. :rtype: requests.Response
Sends a PATCH request. Returns :class:`Response` object. :param url: URL for the new :class:`Request` object. :param data: (optional) Dictionary, list of tuples, bytes, or file-like object to send in the body of the :class:`Request`. :param \*\*kwargs: Optional arguments that ``request`` takes. :rtype: requests.Response
Sends a POST request. Returns :class:`Response` object. :param url: URL for the new :class:`Request` object. :param data: (optional) Dictionary, list of tuples, 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. :rtype: requests.Response
Constructs a :class:`PreparedRequest <PreparedRequest>` for transmission and returns it. The :class:`PreparedRequest` has settings merged from the :class:`Request <Request>` instance and those of the :class:`Session`. :param request: :class:`Request` instance to prepare with this session's settings. :rtype: requests.PreparedRequest
Sends a PUT request. Returns :class:`Response` object. :param url: URL for the new :class:`Request` object. :param data: (optional) Dictionary, list of tuples, bytes, or file-like object to send in the body of the :class:`Request`. :param \*\*kwargs: Optional arguments that ``request`` takes. :rtype: requests.Response
Constructs a :class:`Request <Request>`, prepares it and sends it. Returns :class:`Response <Response>` object. :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, list of tuples, 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 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 :ref:`(connect timeout, read timeout) <timeouts>` 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 or protocol and hostname to the URL of the proxy. :param stream: (optional) whether to immediately download the response content. Defaults to ``False``. :param 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. :param cert: (optional) if String, path to ssl client cert file (.pem). If Tuple, ('cert', 'key') pair. :rtype: requests.Response