473,480 Members | 1,876 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Problem with httplib and HEAD request

Hi -

I'm writing some Python code to interact with Amazon's S3 service. One
feature of S3 is that it will allow you to use the HTTP HEAD request to
retrieve metadata about an S3 object without actually retrieving the
content of the object. In trying to use this feature, I'm running into
what I think is a bug in httplib.py.

If the resource I perform the HEAD request on exists within S3 then
everything is fine. If, however, the resource doesn't exist then a 404
is returned. If the request had been a GET rather than a HEAD the body
of the response would be some XML that gave further information about
the error status returned. However, for a HEAD request no body can be
returned so the body is empty. The error response, for either HEAD or
GET, does include the following header:

transfer-encoding: chunked

And this seems to be causing confusion in httplib.py. I have to call
the read method of the response or else I get a ResponseNotReady
exception on my next request. When I attempt to read the body of the
error response to the HEAD request it is passed onto the _read_chunked
method where it immediately tries to do a readline() on the connection
which, of course, hangs because no body has been sent in the response.

So, I know this is kind of a boundary condition and perhaps it hasn't
come up before but it seems that the behavior of httplib is incorrect.
I think something needs to be added to the _read_chunked method which
checks if the request is a GET and, if so, just reads zero bytes from
the socket and returns.

Any comments? Thanks,

Mitch

Mar 28 '06 #1
1 3065
For what it's worth, I made the following change to httplib.py and it
seems to have solved my problems:

c455
< if self.chunked:
---
if self.chunked and self._method != 'HEAD':


I'm using Python 2.4.1 on MacOS.

Mitch

Mar 29 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1660
by: hitectahir | last post by:
Hi, I have been using a remote data server named Clarens which runs on top of the Apache web server and communicates through xmlrpc on Redhat Linux 7.3. It has been working fine for about a...
4
3788
by: Roger Binns | last post by:
I have just spent several weeks mashing xmlrpc, httplib and SSL (from M2Crypto) to work together. The current standard library has several problems: - Builtin SSL is pretty much useless if you...
2
15906
by: scummer | last post by:
Hi, I am having a problem with the httplib HTTPConnection object. While I can easily send requests that don't have any payload (ie. "get"), I encounter issues if I want to post xml data. If you...
0
1875
by: Milos Prudek | last post by:
How can I set httplib timeout for httplib.request() ? httplib.request timeouts after 3:10 with "socket" timeout error message. I found socket.settimeout() and I believe there is a way to add...
0
2434
by: Terry Kerr | last post by:
Hi, I have an app that makes a https POST to a remote server that I have no control over. The app runs fine in python 2.1.3 with socket.ssl compiled with openssl-0.9.6, however it will not run...
0
1460
by: Laszlo Zsolt Nagy | last post by:
Hello, This is from the docs, from section 11.6.1 (HTTPConnection Objects) HTTPConnection instances have the following methods: request( method, url]) The headers argument should be a...
2
10748
by: spamsink42 | last post by:
this code h=httplib.HTTPConnection('euronext.com') h.request('GET', 'http://www.euronext.com/home/0,3766,1732,00.html') fails with this message File "httplib.py", line 532, in connect...
0
1563
by: Baptiste Lepilleur | last post by:
I activated httplib debug, and when trace are printed, a UnicodeError exception is thrown. I have already set sys.stdout to use utf-8 encoding (this removed the exception when *I* was printing...
0
1882
by: shonen | last post by:
I'm currently attempting to connect to a shoutcast server pull down the information from here and then I'll parse it. I got this working with the httplib, which was great, the problem is I want...
0
7054
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7102
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6756
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
1
4798
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3008
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3000
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1310
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
570
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
199
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.