Python Requests - ChunkedEncodingError(e) - requests.iter_lines

ChunkedEncodingError is caused by: httplib.IncompletedRead

enter image description here

import httplib

def patch_http_response_read(func):
    def inner(*args):
        try:
            return func(*args)
        except httplib.IncompleteRead, e:
            return e.partial
    return inner

httplib.HTTPResponse.read = patch_http_response_read(httplib.HTTPResponse.read)

I think this could be a patch. It allows you to deal with defective http servers.

Most servers transmit all data, but due implementation errors they wrongly close session and httplib raise error and bury your precious bytes.


As I posted here mentioned by another guy IncompleteRead, you can use the "With" clause to make sure that your previous request has closed.

 with requests.request("POST", url_base, json=task, headers=headers) as report:
    print('report: ', report)