checking http response codes in python python

Lasted updated by @craigaddyman on 20 August 2015

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! :)


Subscribe by email