Docstrings-Beispiel#
Main Interface#
- requests.head(url, **kwargs)[Quellcode]#
Sends a HEAD request.
- Parameter:
url – URL for the new
Request
object.**kwargs – Optional arguments that
request
takes. If allow_redirects is not provided, it will be set to False (as opposed to the defaultrequest()
behavior).
- Rückgabe:
Response
object- Rückgabetyp:
requests.Response
Exceptions#
- exception requests.RequestException(*args, **kwargs)[Quellcode]#
There was an ambiguous exception that occurred while handling your request.
Request Sessions#
- class requests.Session[Quellcode]#
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]>
- auth#
Default Authentication tuple or object to attach to
Request
.
- cert#
SSL client certificate default, if String, path to ssl client cert file (.pem). If Tuple, (‚cert‘, ‚key‘) pair.
- close()[Quellcode]#
Closes all adapters and as such the session
- cookies#
A CookieJar containing all currently outstanding cookies set on this session. By default it is a
RequestsCookieJar
, but may be any othercookielib.CookieJar
compatible object.
- delete(url, **kwargs)[Quellcode]#
Sends a DELETE request. Returns
Response
object.- Parameter:
url – URL for the new
Request
object.**kwargs – Optional arguments that
request
takes.
- Rückgabetyp:
requests.Response
- get(url, **kwargs)[Quellcode]#
Sends a GET request. Returns
Response
object.- Parameter:
url – URL for the new
Request
object.**kwargs – Optional arguments that
request
takes.
- Rückgabetyp:
requests.Response
- get_adapter(url)[Quellcode]#
Returns the appropriate connection adapter for the given URL.
- Rückgabetyp:
requests.adapters.BaseAdapter
- get_redirect_target(resp)#
Receives a Response. Returns a redirect URI or
None
- head(url, **kwargs)[Quellcode]#
Sends a HEAD request. Returns
Response
object.- Parameter:
url – URL for the new
Request
object.**kwargs – Optional arguments that
request
takes.
- Rückgabetyp:
requests.Response
- headers#
A case-insensitive dictionary of headers to be sent on each
Request
sent from thisSession
.
- hooks#
Event-handling hooks.
- max_redirects#
Maximum number of redirects allowed. If the request exceeds this limit, a
TooManyRedirects
exception is raised. This defaults to requests.models.DEFAULT_REDIRECT_LIMIT, which is 30.
- merge_environment_settings(url, proxies, stream, verify, cert)[Quellcode]#
Check the environment and merge it with some settings.
- Rückgabetyp:
- mount(prefix, adapter)[Quellcode]#
Registers a connection adapter to a prefix.
Adapters are sorted in descending order by prefix length.
- options(url, **kwargs)[Quellcode]#
Sends a OPTIONS request. Returns
Response
object.- Parameter:
url – URL for the new
Request
object.**kwargs – Optional arguments that
request
takes.
- Rückgabetyp:
requests.Response
- params#
Dictionary of querystring data to attach to each
Request
. The dictionary values may be lists for representing multivalued query parameters.
- patch(url, data=None, **kwargs)[Quellcode]#
Sends a PATCH request. Returns
Response
object.- Parameter:
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
.**kwargs – Optional arguments that
request
takes.
- Rückgabetyp:
requests.Response
- post(url, data=None, json=None, **kwargs)[Quellcode]#
Sends a POST request. Returns
Response
object.- Parameter:
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.
- Rückgabetyp:
requests.Response
- prepare_request(request)[Quellcode]#
Constructs a
PreparedRequest
for transmission and returns it. ThePreparedRequest
has settings merged from theRequest
instance and those of theSession
.- Parameter:
request –
Request
instance to prepare with this session’s settings.- Rückgabetyp:
requests.PreparedRequest
- proxies#
Dictionary mapping protocol or protocol and host to the URL of the proxy (e.g. {‚http‘: ‚foo.bar:3128‘, ‚http://host.name‘: ‚foo.bar:4012‘}) to be used on each
Request
.
- put(url, data=None, **kwargs)[Quellcode]#
Sends a PUT request. Returns
Response
object.- Parameter:
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
.**kwargs – Optional arguments that
request
takes.
- Rückgabetyp:
requests.Response
- rebuild_auth(prepared_request, response)#
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.
- rebuild_method(prepared_request, response)#
When being redirected we may want to change the method of the request based on certain specs or browser behavior.
- rebuild_proxies(prepared_request, proxies)#
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).
This method also replaces the Proxy-Authorization header where necessary.
- Rückgabetyp:
- 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)[Quellcode]#
Constructs a
Request
, prepares it and sends it. ReturnsResponse
object.- Parameter:
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
.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 or protocol and hostname to the URL of the proxy.
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 toFalse
, 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 toFalse
may be useful during local development or testing.cert – (optional) if String, path to ssl client cert file (.pem). If Tuple, (‚cert‘, ‚key‘) pair.
- Rückgabetyp:
requests.Response
- resolve_redirects(resp, req, stream=False, timeout=None, verify=True, cert=None, proxies=None, yield_requests=False, **adapter_kwargs)#
Receives a Response. Returns a generator of Responses or Requests.
- send(request, **kwargs)[Quellcode]#
Send a given PreparedRequest.
- Rückgabetyp:
requests.Response
- should_strip_auth(old_url, new_url)#
Decide whether Authorization header should be removed when redirecting
- stream#
Stream response content default.
- trust_env#
Trust environment settings for proxy configuration, default authentication and similar.
- verify#
SSL Verification default. Defaults to True, requiring requests to verify the TLS certificate at the remote end. If verify is 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. Only set this to False for testing.