2
votes

According http://www.w3.org/Protocols/rfc2616/rfc2616-sec8.html#sec8.2.3 client has to wait for 100 (Continue) status, before making POST (on HTTP 1.1 server that requires this header).

I can't understand how can Python do this. For example:

conn = httplib.HTTPConnection(url)
conn.putrequest('POST', page)
conn.putheader(...)
conn.putheader('Expect', '100-continue')
conn.endheaders()

Now, I don't see other options then send the data:

conn.send(data)

in which case I get error, when asking for response:

error: [Errno 10053] An established connection was aborted by the software in your host machine

How can I ask for status 100, so that I can send the data?

1
I don't think httplib supports this (very well); see the discussion in this requests ticket (specifically the and can close the socket early in a way that breaks httplib remark).Martijn Pieters
If you read the exception message, you will see that the connection was aborted. Is the network okay? Did you pull a network cable? Is there a firewall with DPI that stops POST http requests?Some programmer dude
I guess we can't expect meaningful exception in this case. I don't have problem with with my network, and same code in Java for example works as expected.theta
@MartijnPieters, do you know of another library that supports this header?theta
@theta: Augie Fackler (durin42) mentions httpplus, but I have not tried anything in this direction myself. A quick glance at the code does show promise.Martijn Pieters

1 Answers

3
votes

I don't think httplib supports this (very well); see the discussion in this requests ticket, specifically

and can close the socket early in a way that breaks httplib

The author of that comment, Augie Fackler (durin42) also mentions his own httpplus library.

A quick glance at the source code shows promise that it does handle Expect: 100-Continue correctly:

# handle 100-continue response
hdrs, body = self.raw_response.split(self._end_headers, 1)
http_ver, status = hdrs.split(' ', 1)
if status.startswith('100'):
    self.raw_response = body
    self.continued = True
    logger.debug('continue seen, setting body to %r', body)
    return