3

I am receiving a the error requests.exceptions.ChunkedEncodingError: ('Connection broken: IncompleteRead(0 bytes read)', IncompleteRead(0 bytes read)) from a server using the Request package in Python.

It is my understanding from the post How to tell the HTTP server to not send chunked encoding that one way around this is to tell the server not to send chunked encoding, specifically by specifying HTTP/1.0 in the request.

How do i go about doing this using the Requests package?

Community
  • 1
  • 1
kyrenia
  • 5,431
  • 9
  • 63
  • 93
  • Possible duplicate of [How to define the HTTP protocol version in requests?](http://stackoverflow.com/questions/31728124/how-to-define-the-http-protocol-version-in-requests) – Anonymous Jun 14 '16 at 16:57

1 Answers1

4

You can try setting the HTTP version used in the httplib backend used by Requests.

On Python 2, you can do that like so:

import httplib
httplib.HTTPConnection._http_vsn = 10
httplib.HTTPConnection._http_vsn_str = 'HTTP/1.0'

and with Python 3, httplib was renamed http.client, so you'd do

import http.client
http.client.HTTPConnection._http_vsn = 10
http.client.HTTPConnection._http_vsn_str = 'HTTP/1.0'

Issue 2341 on Requests' GitHub shows that at least one person has done it this way—and also that it is definitely NOT SUPPORTED by Requests. In particular, the library will make no effort to ensure that only HTTP/1.0 compatible headers are sent, so stuff could very well break.

There is no supported way to set the HTTP protocol version with the Requests library.

Nick Matteo
  • 4,453
  • 1
  • 24
  • 35