The requests Package
Last updated
Was this helpful?
Last updated
Was this helpful?
Prerequisite: and
The requests
package provides an easy way for Python programs to issue HTTP requests, whether scraping the contents of a web page, or exchanging data with an API.
Reference:
First install the package, if necessary:
Issue a "GET" request (perhaps the most common):
In addition to "GET" requests, you can also issue other types of requests like "POST", "PUT", and "DELETE", sending data to the server as necessary:
Example POST request:
If the response contains JSON, you can use to parse it:
If the response contains data in CSV format, you can use the familiar CSV-processing mechanisms like the or , with some possible modifications for parsing a CSV-formatted string instead of a CSV file.
If the response contains data in HTML or XML format, you can use to parse it.