I found another (simpler) solution here: http://www.piware.de/2011/01/creating-an-https-server-in-python/
This is my working porting to python3:
from http.server import HTTPServer,SimpleHTTPRequestHandler
from socketserver import BaseServer
import ssl
httpd = HTTPServer(('localhost', 1443), SimpleHTTPRequestHandler)
httpd.socket = ssl.wrap_socket (httpd.socket, certfile='certificate.pem', server_side=True)
httpd.serve_forever()
Answer from Antonio Ragagnin on Stack OverflowGitHub
github.com › vmware › pyvmomi › issues › 1057
Python 3.12 issue with wrap_socket (deprecated in 3.7) · Issue #1057 · vmware/pyvmomi
November 21, 2023 - Remove the ssl.wrap_socket() function, deprecated in Python 3.7: instead, create a ssl.SSLContext object and call its ssl.SSLContext.wrap_socket method. Any package that still uses ssl.wrap_socket() is broken and insecure.
Author ekrichbaum
Trac Project
trac.edgewall.org › ticket › 13749
#13749 (Remove the ssl.wrap_socket() function, deprecated in Python 3.7) – The Trac Project
Serving on 0.0.0.0:3000 view at https://127.0.0.1:3000/ Using HTTP/1.1 protocol version Traceback (most recent call last): File "/home/jun66j5/src/tracdev/git/trac/web/standalone.py", line 392, in <module> main() File "/home/jun66j5/src/tracdev/git/trac/web/standalone.py", line 381, in main serve() File "/home/jun66j5/src/tracdev/git/trac/web/standalone.py", line 344, in serve httpd.socket = ssl.wrap_socket(httpd.socket, server_side=True, ^^^^^^^^^^^^^^^ AttributeError: module 'ssl' has no attribute 'wrap_socket' Fixed in [17784] and merged in [17785]. Note: See TracTickets for help on using tickets.
GitHub
github.com › web-platform-tests › wpt › issues › 44427
DeprecationWarning: ssl.wrap_socket() is deprecated, use SSLContext.wrap_socket() · Issue #44427 · web-platform-tests/wpt
February 6, 2024 - DeprecationWarning: ssl.wrap_socket() is deprecated, use SSLContext.wrap_socket()#44427 · Copy link · Labels · infrawptserve · gsnedders · opened · on Feb 6, 2024 · Issue body actions · We don't seem to have had any tests for the H1 ...
Author gsnedders
Top answer 1 of 2
18
I found another (simpler) solution here: http://www.piware.de/2011/01/creating-an-https-server-in-python/
This is my working porting to python3:
from http.server import HTTPServer,SimpleHTTPRequestHandler
from socketserver import BaseServer
import ssl
httpd = HTTPServer(('localhost', 1443), SimpleHTTPRequestHandler)
httpd.socket = ssl.wrap_socket (httpd.socket, certfile='certificate.pem', server_side=True)
httpd.serve_forever()
2 of 2
16
Since Python 3.7 ssl.wrap_socket is deprecated, use SSLContext.wrap_socket instead:
check: https://docs.python.org/3.7/library/ssl.html#ssl.wrap_socket
and since version 3.10: SSLContext without protocol argument is deprecated.
check: https://docs.python.org/3.10/library/ssl.html#ssl.SSLContext
from http.server import HTTPServer,SimpleHTTPRequestHandler
import ssl
httpd = HTTPServer(('localhost', 1443), SimpleHTTPRequestHandler)
# Since version 3.10: SSLContext without protocol argument is deprecated.
# sslctx = ssl.SSLContext()
sslctx = ssl.SSLContext(ssl.PROTOCOL_TLS_SERVER)
sslctx.check_hostname = False # If set to True, only the hostname that matches the certificate will be accepted
sslctx.load_cert_chain(certfile='certificate.pem', keyfile="private.pem")
httpd.socket = sslctx.wrap_socket(httpd.socket, server_side=True)
httpd.serve_forever()
GitHub
github.com › fkie-cad › socbed › issues › 89
Replace fully deprecated ssl.wrap_socket() with ssl.SSLContext.wrap_socket() (Python 3.12+) · Issue #89 · fkie-cad/socbed
October 14, 2024 - The ssl.wrap_socket() method, which has been deprecated in Python 3.7, has now been removed in Python 3.12. Consequently, our vmconsole no longer works, and we need to update our code accordingly. ...
Author Maspital
Semgrep
semgrep.dev › playground › r › YDT8XN › python.lang.security.audit.ssl-wrap-socket-is-deprecated.ssl-wrap-socket-is-deprecated
ssl-wrap-socket-is-deprecated
You need to enable JavaScript to run this app
GitHub
github.com › zyn3rgy › LdapRelayScan › pull › 14
ssl.wrap_socket deprecation fix by evanmiller2112 · Pull Request #14 · zyn3rgy/LdapRelayScan
This just implements the SSLContext.wrap_socket function as recommended in the Python spec: Deprecated since version 3.7: Since Python 3.2 and 2.7.9, it is recommended to use the SSLContext.wrap_socket() instead of wrap_socket().
Author zyn3rgy
Red Hat
bugzilla.redhat.com › show_bug.cgi
1565943 – Don't recommend ssl.wrap_socket()
April 11, 2018 - RHEL Engineering is moving the tracking of its product development work on RHEL 6 through RHEL 9 to Red Hat Jira (issues.redhat.com). If you're a Red Hat customer, please continue to file support cases via the Red Hat customer portal. If you're not, please head to the "RHEL project" in Red ...
GitHub
github.com › celery › py-amqp › pull › 327
Stop to use deprecated method ssl.wrap_socket by 4383 · Pull Request #327 · celery/py-amqp
The top-level function is limited and creates an insecure client socket without server name indication or hostname matching [1]. Python 2.7 is now officially unmaintained, latest version of python 2.7 is 2.7.18, py-amqp only support python versions who are compatible with these changes [2]. These changes move away from ssl.wrap_socket by using now ssl.SSLContext.wrap_socket [3].
Author celery
GitHub
github.com › zyn3rgy › LdapRelayScan › issues › 9
Deprecation Warning `ssl.wrap_socket()` · Issue #9 · zyn3rgy/LdapRelayScan
May 5, 2022 - On Python 3.10.4 I get the following deprecation warning when running the tool. LdapRelayScan.py:121: DeprecationWarning: ssl.wrap_socket() is deprecated, use SSLContext.wrap_socket()
Author exploide
GitHub
github.com › eventlet › eventlet › issues › 795
[Python 3.12] AttributeError: module 'ssl' has no attribute 'wrap_socket' · Issue #795 · eventlet/eventlet
April 3, 2023 - From What's new: Remove the ssl.wrap_socket() function, deprecated in Python 3.7: instead, create a ssl.SSLContext object and call its ssl.SSLContext.wrap_socket method. Any package that still uses ssl.wrap_socket() is broken and insecure.
Author hrnciar
GitHub
github.com › pajbot › pajbot › issues › 2795
`ssl.wrap_socket` removed in Python 3.12 · Issue #2795 · pajbot/pajbot
January 2, 2025 - Remove the ssl.wrap_socket() function, deprecated in Python 3.7: instead, create a ssl.SSLContext object and call its ssl.SSLContext.wrap_socket method. Any package that still uses ssl.wrap_socket() is broken and insecure.
Author IS2511
Pythontic
pythontic.com › ssl › sslcontext › wrap_socket
wrap_socket() method of SSLContext class in Python | Pythontic.com
Given a connection oriented socket, the SSLContext.wrap_socket() method returns an SSLSocket. The method copies the attributes/options of the socket instance and creates an SSLSocket. The original socket is detached.