class Session(SessionRedirectMixin):
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 |
Returns | |
requests.adapters.BaseAdapter | Undocumented |
Returns | |
dict | Undocumented |
Registers a connection adapter to a prefix.
Adapters are sorted in descending order by prefix length.
Response
object.Parameters | |
url | URL 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 . |
**kwargs | Optional arguments that request takes. |
Returns | |
requests.Response | Undocumented |
PreparedRequest
for
transmission and returns it. The PreparedRequest
has settings
merged from the Request
instance and those of the
Session
.Parameters | |
request | Request instance to prepare with this
session's settings. |
Returns | |
requests.PreparedRequest | Undocumented |
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, 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. |
hooks | Undocumented |
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.Response | Undocumented |