requests¶
Requests HTTP library¶
Requests is an HTTP library, written in Python, for human beings. Basic GET usage:
>>> import requests
>>> r = requests.get('https://www.python.org')
>>> r.status_code
200
>>> 'Python is a programming language' in r.content
True
... or POST:
>>> payload = dict(key1='value1', key2='value2')
>>> r = requests.post('http://httpbin.org/post', data=payload)
>>> print(r.text)
{
...
"form": {
"key2": "value2",
"key1": "value1"
},
...
}
The other HTTP methods are supported - see requests.api. Full documentation is at <http://python-requests.org>.
| copyright: |
|
|---|---|
| license: | Apache 2.0, see LICENSE for more details. |
Functions¶
delete(url, **kwargs) |
Sends a DELETE request. |
get(url[, params]) |
Sends a GET request. |
head(url, **kwargs) |
Sends a HEAD request. |
options(url, **kwargs) |
Sends a OPTIONS request. |
patch(url[, data]) |
Sends a PATCH request. |
post(url[, data, json]) |
Sends a POST request. |
put(url[, data]) |
Sends a PUT request. |
request(method, url, **kwargs) |
Constructs and sends a Request. |
session() |
Returns a Session for context-management. |
Classes¶
NullHandler([level]) |
This handler does nothing. |
PreparedRequest() |
The fully mutable PreparedRequest object, containing the exact bytes that will be sent to the server. |
Request([method, url, headers, files, data, ...]) |
A user-created Request object. |
Response() |
The Response object, which contains a server’s response to an HTTP request. |
Session() |
A Requests session. |
Exceptions¶
ConnectTimeout(*args, **kwargs) |
The request timed out while trying to connect to the remote server. |
ConnectionError(*args, **kwargs) |
A Connection error occurred. |
DependencyWarning |
Warned when an attempt is made to import a module with missing optional dependencies. |
FileModeWarning |
A file was opened in text mode, but Requests determined its binary length. |
HTTPError(*args, **kwargs) |
An HTTP error occurred. |
ReadTimeout(*args, **kwargs) |
The server did not send any data in the allotted amount of time. |
RequestException(*args, **kwargs) |
There was an ambiguous exception that occurred while handling your request. |
Timeout(*args, **kwargs) |
The request timed out. |
TooManyRedirects(*args, **kwargs) |
Too many redirects. |
URLRequired(*args, **kwargs) |
A valid URL is required to make a request. |