Tutorial by Examples

python-requests is available on PyPI, the Python Package Index, which means it can be installed through pip: pip install requests Up-to-date source code can be found on the requests GitHub repository If you wish to install it from source, you can do this by either cloning the GitHub repository:...
requests.get() creates a GET request: response = requests.get('https://example.com/') Pass in query parameters as a dictionary to the params argument: response = requests.get('https://example.com/', params={"a": 1, "b": 2}) For GET requests that might require basic authen...
POST requests are made with the request.post() method. If you need to send a web form request as a POST body, pass in a dictionary with key-value pairs as the data argument; requests will encode these to a application/x-www-form-urlencoded mimetype body: r = requests.post('https://github.com/', d...
The requests module has top-level functions for most HTTP methods: r = requests.put('https://example.com/', data=put_body) r = requests.delete('https://example.com/') r = requests.head('https://example.com/') r = requests.options('https://example.com/') r = requests.patch('https://example.com/'...
response = requests.get("https://api.github.com/events") text_resp = response.text JSON response: for json-formatted responses the package provides a built-in decoder response = requests.get('https://api.github.com/events') json_resp = response.json() This method will raise a Valu...
The attribute status_code contains the status code of the response good_req = requests.get('https://api.github.com/events') code_200 = good_req.status_code notfound_req = requests.get('https://api.github.com/not_found') code_404 = notfound_req.status_code requests.codes.__dict__ will provid...

Page 1 of 1