I just want to test that a given website is up or not from a python
script. I thought of using wget as an os command. Any better ideas?
thanks
moe smadi
>hi;
>
>I just want to test that a given website is up or not from a python
>script. I thought of using wget as an os command. Any better ideas?
>
>
urllib
http://www.python.org/doc/current/lib/module-urllib.html
If you only want to test if the HTTP port is open or not:
socket
http://docs.python.org/lib/module-socket.html
Les
matt
If you want to test web sites, you might be interested in
zope.testbrowser (currently Zope 3 only, but fixing that is on my to do
list).
You can see an example testbrowser test (which is also both its README
and its unit tests) at
http://svn.zope.org/*checkout*/Zope3/branches/testbrowser-integration/src/zope/testbrowser/README.txt?rev=38050
If there is any interest I'll try to package up a stand-alone version in
the next few days.
--
Benji York
> If there is any interest I'll try to package up a stand-alone version in
> the next few days.
I think that would be a very usefull tool. Currently I'm using httpunit
with Jython but a python only tool would be much nicer.
regards,
Achim
Have you looked into twill? It's available at
<http://www.python.org/pypi/twill/0.7.2>
Grig
> I just want to test that a given website is up or not from a python
> script. I thought of using wget as an os command. Any better ideas?
Here is how I did it:
import urllib2
import socket
def checkUrl(url, timeout=1):
"""Checks an url for a python version greater
than 2.3.3.
Note: For me isn't important the kind of
HTTP Error. If you want to know it,
then take a look at the existent
solutions like CMFLinkChecker and
see how they extract the code from
the error message.
"""
error={'code':1, 'msg':'Success'}
defTimeOut=socket.getdefaulttimeout()
socket.setdefaulttimeout(timeout)
try:
urllib2.urlopen(url)
except (urllib2.HTTPError, urllib2.URLError,
socket.error, socket.sslerror):
error['code']=-2
error['msg']="The link: \"${link}\" couldn't be validated"
except:
socket.setdefaulttimeout(defTimeOut)
raise
socket.setdefaulttimeout(defTimeOut)
return error
I put a first cut at http://benjiyork.com/zope.testbrowser-0.1.tgz).
See the README.txt for general info and over_the_wire.txt for how to use
it to access web sites. It requires the zope.interface package from
http://www.zope.org/Products/ZopeInterface (version 3.0.1 should work).
--
Benji York