>>> import httplib
>>> conn = httplib.HTTPConnection("www.google.com")
>>> conn.request("HEAD", "/index.html")
>>> res = conn.getresponse()
>>> print res.status, res.reason
200 OK
This code will get the HTTP status code. However, notice that I split up “google.com” and “/index.html” on 2 lines.
And it’s confusing.
What if I want to find the status code of just a general URL???
http://mydomain.com/sunny/boo.avi
http://anotherdomain.com/rss/fee.xml
Can’t I just stick the URL into it, and make it work?
Edit…I cannot use urllib, because I don’t want to downlaod the file
Alternatively, if you expect that actually downloading the data is problematic and you really need the
HEADmethod, you could parse the URL usingurlparse:And wrap this into a function taking the URL as an argument.