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

How to do a Http HEAD requests

4 views
Skip to first unread message

Soni Bergraj

unread,
Dec 11, 2006, 4:13:00 PM12/11/06
to pytho...@python.org
Hello list,
I was just wondering if there is a more convenient way of doing a Http
HEAD requests then the socket module?

Any ideas?

Cheers,
--
Soni Bergraj
http://www.YouJoy.org/

Tim Roberts

unread,
Dec 12, 2006, 1:48:56 AM12/12/06
to
Soni Bergraj <sonib...@youjoy.org> wrote:
>
>I was just wondering if there is a more convenient way of doing a Http
>HEAD requests then the socket module?
>
>Any ideas?

The standard "httplib" module can do that in a half-dozen lines of code.
--
Tim Roberts, ti...@probo.com
Providenza & Boekelheide, Inc.

Gerard Flanagan

unread,
Dec 12, 2006, 9:16:37 AM12/12/06
to

Soni Bergraj wrote:

> Hello list,
> I was just wondering if there is a more convenient way of doing a Http
> HEAD requests then the socket module?
>
> Any ideas?

I recently used this:

http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/286225

Gerard

Fredrik Lundh

unread,
Dec 12, 2006, 9:34:12 AM12/12/06
to pytho...@python.org
Soni Bergraj wrote:

> I was just wondering if there is a more convenient way of doing a Http
> HEAD requests then the socket module?

quick version:

>>> import urllib2
>>> request = urllib2.Request("http://www.python.org")
>>> request.get_method = lambda: "HEAD"
>>> http_file = urllib2.urlopen(request)
>>> http_file.headers
<httplib.HTTPMessage instance at 0x00C711E8>
>>> http_file.headers["content-type"]
'text/html'
>>> print http_file.headers
Date: Tue, 12 Dec 2006 14:33:08 GMT
Server: Apache/2.0.54 (Debian GNU/Linux) DAV/2 SVN/1.1.4 mod_python/3.1.3 Python
/2.3.5 mod_ssl/2.0.54 OpenSSL/0.9.7e
Last-Modified: Tue, 12 Dec 2006 07:04:52 GMT
ETag: "61b82-2fd2-e60f4d00"
Accept-Ranges: bytes
Content-Length: 12242
Connection: close
Content-Type: text/html

</F>

0 new messages