DEV Community

loading...

Discussion on: Get HTTP response codes with Python

Collapse
rhymes profile image
rhymes

Since you only need to check response codes you might want to only issue a HEAD request, this way you avoid downloading the page and discard the content.

If you want to use the standard library you can do something like:

request = urllib.request.Request(url, method="HEAD")
response = urllib.request.urlopen(request)

Unfortunately this will follow redirects, so you end up issuing multiple requests.

I'm sure there's a way to ignore redirects but you'd have to check the documentation.

Collapse
petercour profile image
petercour Author

Thanks!