DEV Community 👩‍💻👨‍💻

Discussion on: Get HTTP response codes with Python

rhymes profile image

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.

petercour profile image
petercour Author