Status codes are helpful in letting us know the result, once a request is sent. To know about this, we can use
>>> r = requests.get('http://google.com') >>> r.status_code 200
To make it much easier to deal with
status_codes, Requests has got a built-in status code lookup object which serves as an easy reference. We must compare the
r.status_code to achieve this. If the result turns out to be
True, then it's
200 status code, and if it's
False, it's not. We can also compare the
requests.code.all_good to get the lookup work.
>>> r = requests.get('http://google.com') >>> r.status_code == requests.codes.ok True
Now, let's try checking with ...