Main Interface¶
All of Requests’ functionality can be accessed by these 7 methods.
They all return an instance of the Response object.
- requests.request(method, url, **kwargs)[source]¶
Constructs and sends a
Request.- Parameters:
method – method for the new
Requestobject:GET,OPTIONS,HEAD,POST,PUT,PATCH, orDELETE.url – URL for the new
Requestobject.params – (optional) Dictionary, list of tuples or bytes to send 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) A JSON serializable Python 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
'name': file-like-objects(or{'name': file-tuple}) for multipart encoding upload.file-tuplecan be a 2-tuple('filename', fileobj), 3-tuple('filename', fileobj, 'content_type')or a 4-tuple('filename', fileobj, 'content_type', custom_headers), where'content-type'is a string defining the content type of the given file andcustom_headersa dict-like object containing additional headers to add for the file.auth – (optional) Auth tuple to enable Basic/Digest/Custom HTTP Auth.
timeout (float or tuple) – (optional) How many seconds 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) Boolean. Enable/disable GET/OPTIONS/POST/PUT/PATCH/DELETE/HEAD redirection. Defaults to
True.proxies – (optional) Dictionary mapping protocol to the URL of the proxy.
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.stream – (optional) if
False, the response content will be immediately downloaded.cert – (optional) if String, path to ssl client cert file (.pem). If Tuple, (‘cert’, ‘key’) pair.
- Returns:
Responseobject- Return type:
Usage:
>>> import requests >>> req = requests.request('GET', 'https://httpbin.org/get') >>> req <Response [200]>
- requests.head(url, **kwargs)[source]¶
Sends a HEAD request.
- Parameters:
- Returns:
Responseobject- Return type:
- requests.get(url, params=None, **kwargs)[source]¶
Sends a GET request.
- Parameters:
- Returns:
Responseobject- Return type:
- requests.post(url, data=None, json=None, **kwargs)[source]¶
Sends a POST request.
- Parameters:
- Returns:
Responseobject- Return type:
- requests.put(url, data=None, **kwargs)[source]¶
Sends a PUT request.
- Parameters:
- Returns:
Responseobject- Return type:
- requests.patch(url, data=None, **kwargs)[source]¶
Sends a PATCH request.
- Parameters:
- Returns:
Responseobject- Return type: