What is HTTP Response?
The server's response confirms that the server has received the request from the client and has processed it. If the server returned a 200x status code, this usually means that the server completed the request successfully. If an error occurs while executing a client request, the server typically responds with a 400x or 500x error message and provides additional information in the body of the message. Server responses usually come in HTML, plain text, JSON, or XML format.
The HTTP response contains:
1. The Status Line, which shows the HTTP version number, a three-digit number indicating the result of the request, and the reason phrase(status text).
Where:
- HTTP/1.1: the HTTP version
- 200: the status code
- OK: the reason phrase
2. HTTP headers or server header fields contain information that the client can use to learn more about the response and the server that sent it. This information can help the client display a response to the user, store (or cache) the response for future use, and make additional requests to the server now or in the future.
3. The body of the HTTP message contains the resource requested by the client from the server. The server does not return a message-body for the HEAD.
What is the Python Requests library?
Requests Library is a most popular Library that makes it straightforward to send HTTP requests using POST, GET and PUT methods, post JSON and XML data, upload files, and submit HTML forms. The Library automatically validates server SSL certificates and supports session cookies and International Domain Names. The Requests Library is established on the urllib3 library and disguises the complexness of making HTTP requests behind a simple API. The Requests Library is not contained in the Python distribution, almost everyone uses Requests Library because the Python code for working with HTTP becomes simple, short, and straightforward.
How to use the Python Requests library?
To install the Python Requests library, run the following command:
After installing the Request Library, you can use it in your work:
See also
- How do I get JSON using the Python Requests?
- How do I use session objects in Python Requests?
- How do I set a timeout in Python Requests?
- How do I post JSON using the Python Requests Library?
- How do I send a POST request using Python Requests Library?
- How do I send a GET request using Python Requests Library?