http.client.RemoteDisconnected: Remote end closed connection without response
Ideas on how to resolve or mitigate:
- use
urllib3.Retry
like so (docs)adapter = HTTPAdapter(max_retries=Retry( total=5, backoff_factor=0.1, status_forcelist=[429, 500, 502, 503, 504], method_whitelist=["HEAD", "GET", "OPTIONS"] )) session = requests.Session() session.mount("http://", adapter) session.mount("https://", adapter) rsp = session.post(url, json=my_json, params=my_params)
- increase socket keepalive settings like so
import socket from urllib3.connection import HTTPConnection HTTPConnection.default_socket_options = ( HTTPConnection.default_socket_options + [ (socket.SOL_SOCKET, socket.SO_KEEPALIVE, 1), (socket.SOL_TCP, socket.TCP_KEEPIDLE, 45), (socket.SOL_TCP, socket.TCP_KEEPINTVL, 10), (socket.SOL_TCP, socket.TCP_KEEPCNT, 6) ] )
-
set keep-alive in the headersthis is already done by{'Connection': 'keep-alive'}
itkdb
orrequests
by default it seems (probably because of thestream=True
option
It could additionally be related to the 100 Continue
mechanism that I was not expecting to exist for GET
requests but...
Edited by Giordon Holtsberg Stark