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

une lib HTTP permettant d'obtenir le code HTTP?

16 views
Skip to first unread message

Kevin Denis

unread,
Feb 24, 2012, 3:29:47 AM2/24/12
to
Bonjour,

sous python 2.4.2 je dois écrire un script qui doit
récupérer le code retour HTTP de différentes pages web.

Je dois tester aussi bien:
http://www.domaine.com/
que
http://www.domaine.com/dir/subdir/page.html

et je dois trouver pour chacune des ces URLs le code retour HTTP
pour celles-ci. Par exemple,
http://www.domaine.com Code 200 OK
http://www.domaine.com/dir/subdir/page.html Code 404 Not Found
ou les codes 302, etc...

Savez vous s'il existe une lib toute prête qui fait déjà ça ou
approchant?

Merci
--
Kevin

Alain Ketterlin

unread,
Feb 24, 2012, 3:52:34 AM2/24/12
to

Kevin Denis

unread,
Feb 24, 2012, 4:19:27 AM2/24/12
to
Le 24-02-2012, Alain Ketterlin <al...@dpt-info.u-strasbg.fr> a écrit :

>> sous python 2.4.2

> http://lmgtfy.com/?q=python+lib+http&l=1
>
ha ha.
Bon, je cherche avec urrlib, mais avec python 2.4:
>>> obj = urllib.urlopen("http://domaine.tld")
>>> obj.getcode()
Traceback (most recent call last):
File "<stdin>", line 1, in ?
AttributeError: addinfourl instance has no attribute 'getcode'
>>>
--
Kevin

Thomas NOEL

unread,
Feb 24, 2012, 4:24:42 AM2/24/12
to
On 24 fév, 09:52, Alain Ketterlin <al...@dpt-info.u-strasbg.fr> wrote:
> Kevin Denis <ke...@nowhere.invalid> writes:
> >http://www.domaine.com Code 200 OK
> >http://www.domaine.com/dir/subdir/page.htmlCode 404 Not Found
> > ou les codes 302, etc...
> > Savez vous s'il existe une lib toute prête qui fait déjà ça ou
> > approchant?
> http://lmgtfy.com/?q=python+lib+http&l=1

oui, et aussi http://docs.python-requests.org

--
Thomas

Kevin Denis

unread,
Feb 24, 2012, 4:38:08 AM2/24/12
to
Le 24-02-2012, Kevin Denis <ke...@nowhere.invalid> a écrit :
>>> sous python 2.4.2
>
Avec httplib, ça fonctionne. En 2.4.2 il n'y a pas de notion de
timeout, dommage:
>>> c = httplib.HTTPConnection("10.0.0.47")
>>> c.request("HEAD", "/")
>>> r = c.getresponse()
>>> print r.status
200
--
Kevin
0 new messages