Quantcast
Channel: Active questions tagged https - Stack Overflow
Viewing all articles
Browse latest Browse all 1818

Python http.server requests gets reset (RST) connection after every request using curl when trying to run HTTPS server

$
0
0

With Curl I get the data correcty, but after connection:

command:curl https://172.17.0.1:8443

Result:

<html><data>....</data>...curl: (56) OpenSSL SSL_read: error:0A000126:SSL routines::unexpected eof while reading, errno 0

Same behaviour with all HTTP requests. Not occuring when not using SSL.

Example code:

class HTTPRequestHandler(BaseHTTPRequestHandler):    def do_GET(self):        dir_path = os.path.dirname(__file__)        full_path = os.path.join(dir_path, "test.html")        if os.path.isfile(full_path):            try:                with open(full_path, 'rb') as file:                    self.send_response(200)                    self.send_header("Content-type", "text/html")                    self.end_headers()                    self.wfile.write(bytes(file.read()))            except Exception as e:                self.send_error(500, f"Error reading file: {e}")def get_ssl_context(certfile, keyfile):    context = ssl.SSLContext(ssl.PROTOCOL_TLS_SERVER)    context.load_cert_chain(certfile, keyfile)    return context### RUN THE SERVER ###def run(port=8443):    httpd = ThreadingHTTPServer(server_address=('0.0.0.0', port),    RequestHandlerClass=HTTPRequestHandler)    context = get_ssl_context(certfile="http_server/cert.pem", keyfile="http_server/key.pem")    httpd.socket = context.wrap_socket(httpd.socket, server_side=True, suppress_ragged_eofs=False)    try:        httpd.serve_forever()

No errors when reaching local server through browser or postman, I guess they don't mind about the connection reset?

When looking with wireshark, this RST happens when using curl:wireshark

But using curl for online sites for example does not have issues.

Tried looking packet transfers with wireshark.Added ssl cert to trusted certs.Ran also lighttpd server locally (with https configured) and same problem does not occur.

If you add sleep in the end of do_GET function, connection RESET happens only when that function exits, so problem seems to be in closing the request.


Viewing all articles
Browse latest Browse all 1818

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>