Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

testing a website from python

13 views
Skip to first unread message

M.N.A.Smadi

unread,
Sep 20, 2005, 12:13:00 PM9/20/05
to pytho...@python.org
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?

thanks
moe smadi

Laszlo Zsolt Nagy

unread,
Sep 20, 2005, 12:14:33 PM9/20/05
to M.N.A.Smadi, pytho...@python.org
M.N.A.Smadi wrote:

>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

unread,
Sep 20, 2005, 9:06:35 PM9/20/05
to
Here's something I did recently at work. (Thought it's testing http
digest authentication, the idea would the same (testNoAuth() is
probably doing what you want)). It contains unittest code and is using
urllib2.
http://blog.spikesource.com/pyhton_testcases.htm

matt

Benji York

unread,
Sep 21, 2005, 9:20:13 AM9/21/05
to pytho...@python.org, matt
matt wrote:
> Here's something I did recently at work.
> It contains unittest code and is using
> urllib2.
> http://blog.spikesource.com/pyhton_testcases.htm

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

Achim Domma (SyynX Solutions GmbH)

unread,
Sep 21, 2005, 4:24:01 PM9/21/05
to
Benji York wrote:

> 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

Grig Gheorghiu

unread,
Sep 21, 2005, 5:40:39 PM9/21/05
to
Achim,

Have you looked into twill? It's available at
<http://www.python.org/pypi/twill/0.7.2>

Grig

Josef Meile

unread,
Sep 21, 2005, 5:51:27 PM9/21/05
to pytho...@python.org
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?

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

Benji York

unread,
Sep 21, 2005, 10:29:07 PM9/21/05
to Achim Domma (SyynX Solutions GmbH), pytho...@python.org

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

0 new messages