leo
leo

Reputation: 583

I want to test a single web page's response status of many requests(To find out whether there are 404, 5XX requests of this web page)

I am new to python, can anyone tell me which python tools I should use to get my work done? Any good idea to build a python script to automatically find out these 404, 5XX requests?Thanks in advance!

Upvotes: 1

Views: 396

Answers (1)

Abdulla Nilam
Abdulla Nilam

Reputation: 38642

We can check the response status code:

>>> r = requests.get('http://httpbin.org/get')
>>> r.status_code
200

Requests also comes with a built-in status code lookup object for easy reference:

>>> r.status_code == requests.codes.ok
True

If we made a bad request (a 4XX client error or 5XX server error response), we can raise it with Response.raise_for_status():

>>> bad_r = requests.get('http://httpbin.org/status/404')
>>> bad_r.status_code
404

But, since our status_code for r was 200, when we call raise_for_status() we get:

>>> r.raise_for_status()
None

Reffer : this link

Upvotes: 1

Related Questions