all Python 3http.clientexception
http.client.IncompleteRead
exceptions
The response body ended earlier than Content-Length or chunked encoding promised. The part received so far is in the partial attribute.
Syntax
except http.client.IncompleteRead as e: e.partial, e.expected
It usually means the server or a proxy dropped the connection mid-response. The data is not entirely lost: e.partial holds the bytes read so far and e.expected how many were missing. Retrying is safe only for idempotent methods (GET, HEAD), not for POST. Unlike RemoteDisconnected, the headers did arrive; it is the body that was cut off.
Examples
import http.client
import socket
server, client = socket.socketpair()
server.sendall(b'HTTP/1.1 200 OK\r\nContent-Length: 10\r\n\r\nabc')
server.close()
resp = http.client.HTTPResponse(client)
resp.begin()
try:
resp.read()
except http.client.IncompleteRead as e:
print(e) # → IncompleteRead(3 bytes read, 7 more expected)
print(e.partial, e.expected) # → b'abc' 7
client.close()
See also
Open in the full glossarydocs.python.orgReport an inaccuracy