As of 0.10, Werkzeug doesn't support OpenSSL contexts anymore. This decision was made because it is easier to support ssl.SSLContext across Python versions. Your option to re-write this code is this one:

if __name__ == "__main__":
    context = ('cert.crt', 'key.key')
    app.run(host='0.0.0.0', port=80, ssl_context=context, threaded=True, debug=True)

See http://werkzeug.pocoo.org/docs/latest/serving/ for all possibilities.

Answer from Markus Unterwaditzer on Stack Overflow
🌐
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 - This happens because of a change in Python. 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.
Author   hrnciar
Discussions

python - SSL wrap socket: AttributeError: 'module' object has no attribute 'wrap_socket' - Stack Overflow
I'm creating a very simple example on OSX with python 2.6 but I keep getting: Traceback (most recent call last): File "ssl.py", line 1, in import socket, ssl File &... More on stackoverflow.com
🌐 stackoverflow.com
Python 3.12.7 module ssl has no attribute wrap_socket - Stack Overflow
Communities for your favorite technologies. Explore all Collectives · Stack Overflow for Teams is now called Stack Internal. Bring the best of human thought and AI automation together at your work More on stackoverflow.com
🌐 stackoverflow.com
AttributeError("module 'ssl' has no attribute 'wrap_socket'")
Hello, When running warcprox 2.6.1 under Python 3.21, trying to access https-protected urls through warcprox gives the following error: 2024-12-09 13:18:46,072 66069 ERROR MitmProxyHandler(tid=6669... More on github.com
🌐 github.com
2
December 9, 2024
Problem running Flask with an ssl_context under Werkzeug 0.10.1
With the last Werkzeug (0.10.1) I get the following error message: Exception in thread Thread-1: Traceback (most recent call last): File "C:\PGM\Python27\lib\threading.py", line 810, in _... More on github.com
🌐 github.com
11
February 16, 2015
Top answer
1 of 1
1

Per the mysql-connector-python package bug report linked by steeldriver, the cause of the issue appears to be that Python 3.12 removed ssl.wrap_socket (it had been marked deprecated since Python 3.7), but the version of the Python mysql.connector package provided by Ubuntu's python3-mysql.connector package is an old version incompatible with Python 3.12 that expects ssl.wrap_socket to still exist.

From the upstream mysql-connector-python repo, it appears that support for Python 3.12 was first introduced in version v8.2.0. But, in Ubuntu 24.04 LTS, if we apt install python3-msql.connector, inspecting /usr/lib/python3/dist-packages/mysql/connector/version.py and /usr/lib/python3/dist-packages/mysql/connector/network.py shows that it is version v8.0.15, which is not documented as supporting Python 3.12, and attempts to call ssl.wrap_socket are still present inside network.py. So we expect that not to work.

Here's an example following Steeldriver's suggested workaround, avoiding use of the globally installed mysql.connector package provided by ubuntu's python3-mysql.connector package that is incompatible with python3.12, and instead installing a newer version of that package from pypi to an isolated python virtual environment:

$ cat issue.sh

#! /usr/bin/env bash
set -uxo pipefail

python3 -m venv venv
source venv/bin/activate
python3 -m pip install --upgrade mysql-connector-python
python3 test.py
$ cat test.py
import mysql.connector
db = mysql.connector.connect(host="localhost", user="ray", password="...")
print(db)
exit(0)

Run it with chmod +x ./issue.sh && ./issue.sh.

When I run this, it installs version 9.5.0 of the msql-connector-python package.

🌐
Google Groups
groups.google.com › g › comp.lang.python › c › dqpL9cZg3YQ
'module' object has no attribute 'wrap_socket' when use ssl
Traceback (most recent call last): File "crackssl.py", line 16, in <module> wrappedSocket.connect((HOST, PORT)) File "/usr/lib/python2.7/ssl.py", line 433, in connect self._real_connect(addr, False) File "/usr/lib/python2.7/ssl.py", line 420, in _real_connect socket.connect(self, addr) File "/usr/lib/python2.7/socket.py", line 224, in meth return getattr(self._sock,name)(*args) socket.error: [Errno 111] Connection refused martin@ubuntu:~/Documents$ python crackssl.py
🌐
GitHub
github.com › internetarchive › warcprox › issues › 208
AttributeError("module 'ssl' has no attribute 'wrap_socket'") · Issue #208 · internetarchive/warcprox
December 9, 2024 - 2024-12-09 13:18:46,072 66069 ERROR MitmProxyHandler(tid=66699,started=2024-12-09T12:18:46.061680,client=127.0.0.1:39790) warcprox.warcprox.WarcProxyHandler.do_CONNECT(mitmproxy.py:402) problem handling 'CONNECT service.archief.nl:443 HTTP/1.1': AttributeError("module 'ssl' has no attribute 'wrap_socket'")
Author   Grovespaz
🌐
MySQL
bugs.mysql.com › bug.php
MySQL Bugs: #116285: AttributeError: module 'ssl' has no attribute 'wrap_socket'
October 2, 2024 - Description: I receive the following ... self.sock = ssl.wrap_socket( ^^^^^^^^^^^^^^^ AttributeError: module 'ssl' has no attribute 'wrap_socket' ``` This is due to Python 3.12 having removed the ssl.wrap_socket() function (see https://docs.python.org/3.12/whatsnew/3.12.h...
Find elsewhere
🌐
GitHub
github.com › pallets › flask › issues › 1352
Problem running Flask with an ssl_context under Werkzeug 0.10.1 · Issue #1352 · pallets/flask
February 16, 2015 - Exception in thread Thread-1: Traceback (most recent call last): File "C:\PGM\Python27\lib\threading.py", line 810, in __bootstrap_inner self.run() File "C:\PGM\Python27\lib\threading.py", line 763, in run self.__target(*self.__args, **self.__kwargs) File "C:\PGM\Python27\lib\site-packages\werkzeug\serving.py", line 602, in inner passthrough_errors, ssl_context).serve_forever() File "C:\PGM\Python27\lib\site-packages\werkzeug\serving.py", line 506, in make_server passthrough_errors, ssl_context) File "C:\PGM\Python27\lib\site-packages\werkzeug\serving.py", line 450, in __init__ self.socket = ssl_context.wrap_socket(self.socket, AttributeError: 'Context' object has no attribute 'wrap_socket'
Author   Cabu
🌐
Red Hat
bugzilla.redhat.com › show_bug.cgi
2155432 – python-managesieve fails to build with Python 3.12: AttributeError: module 'ssl' has no attribute 'wrap_socket'
Red Hat Bugzilla – Bug 2155432 · This site requires JavaScript to be enabled to function correctly, please enable it · Privacy Contact FAQ Legal
🌐
Wordpress
viewsby.wordpress.com › 2025 › 03 › 11 › fixing-the-ssl-wrap_socket-error-in-pyvmomi-with-python-3-12
Fixing the ssl.wrap_socket Error in pyVmomi with Python 3.12+ | Sany's Linux and Open Source Blog
March 11, 2025 - Traceback (most recent call last): File "/path/to/your/script/usage.py", line 2, in <module> from pyVim.connect import SmartConnect, Disconnect File "/usr/lib/python3/dist-packages/pyVim/connect.py", line 37, in <module> from pyVmomi import vim, vmodl, SoapStubAdapter, SessionOrientedStub File "/usr/lib/python3/dist-packages/pyVmomi/__init__.py", line 204, in <module> from pyVmomi.SoapAdapter import SoapStubAdapter, StubAdapterBase, SoapCmdStubAdapter, \ File "/usr/lib/python3/dist-packages/pyVmomi/SoapAdapter.py", line 993, in <module> _SocketWrapper = ssl.wrap_socket ^^^^^^^^^^^^^^^ AttributeError: module 'ssl' has no attribute 'wrap_socket' The issue occurs because, starting with Python 3.7, the ssl.wrap_socket function has been removed in favor of ssl.SSLContext.wrap_socket.
🌐
Reddit
reddit.com › r/learnpython › mysql problem: "exception has occurred: attributeerror: module 'ssl' has no attribute 'wrap_socket' " on python 3.12.3
r/learnpython on Reddit: MySQL problem: "Exception has occurred: AttributeError: module 'ssl' has no attribute 'wrap_socket' " on python 3.12.3
July 30, 2025 -

OS: Linux Mint 22.1 Cinnamon
IDE: VS Code
Python version: 3.12.3

(apologies for a long post. Half of this is a rant. TL;DR mysql-connector module is installed, but is not connecting due to the SSL having no wrap_socket )

Hey all, this is driving me insane, and its not making sense at all. I'm trying to get MySQL running on my python script and I really want it running...

I've been following the w3schools tutorial on MySQL, and I originally had it connected with no problem. I leave the project to go refactor and maintain my current project. (I didn't touch anything, or install any packages)

When I return, using the same venv and suddenly gives me the error "Module 'ssl' has no attribute 'wrap_socket' " here is the full error. (Pastebin)

Of course, I look up my problem and I find a stack overflow with a similar problem and still not fixed and throwing the same problem. I use pip to uninstall and reinstall mysql-connector-python and still the same problem. I check my installed packages (Pastebin) and its still installed on this venv.

Hell, I even tried the pyOpenSSL and STILL the same problem.

Here's my code:

db = mysql.connector.connect(
    host="localhost",
    user="me-lol", 
    password="WpjrslYpjr",
    database="VeryCoolDB"
    )

# will output when it has
# connected to MySQL server
print("hello world!")

If I find a solution, I will share it, so no poor schmuck like me will have to go though this again.

🌐
Reddit
reddit.com › r › codehunter › comments › qjjdy7 › attributeerror_context_object_has_no_attribute
r/codehunter - AttributeError: 'Context' object has no attribute 'wrap_socket'
October 31, 2021 - File "/usr/lib/python3.4/threading.py", line 920, in _bootstrap_inner self.run() File "/usr/lib/python3.4/threading.py", line 868, in run self._target(*self._args, **self._kwargs) File "/usr/local/lib/python3.4/dist-packages/werkzeug/serving.py", line 602, in inner passthrough_errors, ssl_context).serve_forever() File "/usr/local/lib/python3.4/dist-packages/werkzeug/serving.py", line 506, in make_server passthrough_errors, ssl_context) File "/usr/local/lib/python3.4/dist-packages/werkzeug/serving.py", line 450, in __init__ self.socket = ssl_context.wrap_socket(self.socket,AttributeError: 'Context' object has no attribute 'wrap\_socket'
🌐
GitLab
gitlab.com › hartmut goebel › managesieve › #8
ssl.wrap_socket() function, deprecated in Python 3.7 (#8) · Issues · Hartmut Goebel / managesieve · GitLab
January 6, 2023 - Hi, With Python 3.12. https://docs.python.org/3.12/whatsnew/3.12.html Remove the ssl.wrap_socket() function, deprecated in Python 3.7: instead, create a ssl.SSLContext...
🌐
Python
bugs.python.org › issue16357
Issue 16357: SSLSocket created from SSLContext.wrap_socket doesn't include cert/keyfile - Python tracker
October 29, 2012 - This issue tracker has been migrated to GitHub, and is currently read-only. For more information, see the GitHub FAQs in the Python's Developer Guide · This issue has been migrated to GitHub: https://github.com/python/cpython/issues/60561
🌐
Python
bugs.python.org › issue13721
Issue 13721: ssl.wrap_socket on a connected but failed connection succeeds and .peer_certificate gives AttributeError - Python tracker
January 6, 2012 - This issue tracker has been migrated to GitHub, and is currently read-only. For more information, see the GitHub FAQs in the Python's Developer Guide · This issue has been migrated to GitHub: https://github.com/python/cpython/issues/57930
🌐
Pythonfixing
pythonfixing.com › 2024 › 01 › fixed-ssl-wrap-socket-attributeerror.html
[FIXED] SSL wrap socket: AttributeError: 'module' object has no attribute 'wrap_socket' ~ PythonFixing
Traceback (most recent call last): File "ssl.py", line 1, in <module> import socket, ssl File "/Users/Dennis/ssl.py", line 5, in <module> sslSocket = ssl.wrap_socket(s) AttributeError: 'module' object has no attribute 'wrap_socket'