Python3 CGI HTTPS server fails on Unix

前端 未结 2 575
一向
一向 2021-01-16 05:25

This Python3 CGI HTTPS server used to work a few weeks (or months) ago, but now no longer works under Linux (Ubuntu). I tried on Ubuntu 10.04 and Ubuntu 14.04 and the behavi

2条回答
  •  臣服心动
    2021-01-16 06:00

    I found the answer at:
    http://www.castro.aus.net/~maurice/OddsAndEnds/blog/files/d2baf24c48b972f18836cac7a27734e2-35.html

    The solution is to add:

    http.server.CGIHTTPRequestHandler.have_fork=False # Force the use of a subprocess
    

    before starting the server.

    This is required for Mac and Unix implementation because, for efficiency reasons, they employ a fork to start the process that executes the CGI rather than creating a subprocess as used by other implementations (i.e. Windows). In a non-wrapped CGI implementation the fork works fine and the output is sent to the socket correctly, however, when the socket is SSL wrapped things go terribly wrong.

    The solution is to force the Unix and Mac implementations to use a subprocess leaving the SSL socket happily working and having the Python Server transfer the output of the CGI script to the client while translating the output into SSL.

    I still have no clue why this used to work!

提交回复
热议问题