Head of Digital Marketing @Bronco. Lover of Python and Data.

Checking Http Response Codes In Python

I've just been trying to check for canonical issues on a sites domain and my usual tool of choice was showing response codes that I though were incorrect, it was almost as if there was a Meta refresh happening.

Anyway I wrote a quick script to double check it for me. Here is it...

import requests

url = raw_input('enter url: http://www.')
r = requests.get('http://www.' + url, allow_redirects=False)

print r.status_code
print r.url

I added the user input section simple for ease of use, in case I were to ever use it again.

I can do a slight modification to iterate over a file of URls if I should ever need to. Anyway, just a little problem that I solved within about 3 minutes! :)

Give Your Inbox Some Love

What You'll get?
  • Posts like this delivered straight to your inbox!
  • Nothing else.
Comment Policy

Any code snippets more than a line or 2, please include as a link to a gist

comments powered by Disqus