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 ...

Get Learning Python Network Programming now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.