By using python, how can I check if a website is up? From what I read, I need to check the "HTTP HEAD" and see status code "200 OK", but how to do so ?
Cheers
By using python, how can I check if a website is up? From what I read, I need to check the "HTTP HEAD" and see status code "200 OK", but how to do so ?
Cheers
I think the easiest way to do it is by using Requests module.
If by up, you simply mean "the server is serving", then you could use cURL, and if you get a response than it's up.
I can't give you specific advice because I'm not a python programmer, however here is a link to pycurl http://pycurl.sourceforge.net/.
If server if down, on python 2.7 x86 windows urllib have no timeout and program go to dead lock. So use urllib2
The
HTTPConnection
object from thehttplib
module in the standard library will probably do the trick for you. BTW, if you start doing anything advanced with HTTP in Python, be sure to check outhttplib2
; it's a great library.You could try to do this with
getcode()
from urllibEDIT: For more modern python, i.e.
python3
, use: