Status codes
What if we wanted to know whether anything unexpected had happened to our request? Or what if we wanted to know whether our response contained any data before we read the data out? Maybe we're expecting a large response, and we want to quickly see if our request has been successful without reading the whole response.
HTTP responses provide a means for us to do this through status codes. We can read the status code of a response by using its status
attribute.
>>> response.status 200
Status codes are integers that tell us how the request went. The 200
code informs us that everything went fine.
There are a number of codes, and each one conveys a different meaning. According to their first digit, status codes are classified into the following groups:
- 100: Informational
- 200: Success
- 300: Redirection
- 400: Client error
- 500: Server error
A few of the more frequently encountered codes and their messages are as follows:
200
:OK
404
:Not Found
500
:Internal Server Error
The official...