⬅︎ Back to Best practice with retries with requests
Does not work if requests fails to read a chunked response :(
The following will setup an HTTP server to repro (set the sleep to be greater than your read timeout):import sslfrom time import sleepfrom BaseHTTPServer import BaseHTTPRequestHandler, HTTPServerPORT = 8001class CustomHandler(BaseHTTPRequestHandler): def do_GET(self): print "SLEEP" self.send_response(200) self.send_header('Transfer-Encoding', 'chunked') self.send_header('Content-type', 'text/plain') self.end_headers() self.wfile.write('Hello') sleep(5) self.wfile.write(', world!') print "WAKE" passhttpd = HTTPServer(("", PORT), CustomHandler)httpd.socket = ssl.wrap_socket(httpd.socket, keyfile='/home/local/ANT/schdavid/tmp/key.pem', certfile='/home/local/ANT/schdavid/tmp/cert.pem')try: httpd.serve_forever()except KeyboardInterrupt: print print 'Goodbye' httpd.socket.close()
Comment
Does not work if requests fails to read a chunked response :(
Replies
The following will setup an HTTP server to repro (set the sleep to be greater than your read timeout):
import ssl
from time import sleep
from BaseHTTPServer import BaseHTTPRequestHandler, HTTPServer
PORT = 8001
class CustomHandler(BaseHTTPRequestHandler):
def do_GET(self):
print "SLEEP"
self.send_response(200)
self.send_header('Transfer-Encoding', 'chunked')
self.send_header('Content-type', 'text/plain')
self.end_headers()
self.wfile.write('Hello')
sleep(5)
self.wfile.write(', world!')
print "WAKE"
pass
httpd = HTTPServer(("", PORT), CustomHandler)
httpd.socket = ssl.wrap_socket(httpd.socket, keyfile='/home/local/ANT/schdavid/tmp/key.pem', certfile='/home/local/ANT/schdavid/tmp/cert.pem')
try:
httpd.serve_forever()
except KeyboardInterrupt:
print
print 'Goodbye'
httpd.socket.close()