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

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
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
Anvil-uplink for Python >= 3.12 Solves AttributeError: module 'ssl' has no attribute 'wrap_socket' - Show and Tell - Anvil Community Forum
The main reason why anvil-uplink is incompatible with 3.12 and above is the library it uses for ssl is ws4py found here: ws4py · PyPI The built in ssl library in python was updated to nest a method used by anvil / ws4py behind another connection context object. More on anvil.works
🌐 anvil.works
1
3
March 27, 2024
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
🌐
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
🌐
Anvil
anvil.works › show and tell
Anvil-uplink for Python >= 3.12 Solves AttributeError: module 'ssl' has no attribute 'wrap_socket' - Show and Tell - Anvil Community Forum
March 27, 2024 - The main reason why anvil-uplink is incompatible with 3.12 and above is the library it uses for ssl is ws4py found here: ws4py · PyPI The built in ssl library in python was updated to nest a method used by anvil / ws4py behind another connection context object.
🌐
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 ... deprecated in Python 3.7 and fully removed in Python 3.12. One solution is to create a SSLContext using ssl.create_default_context() and use the context instance's .wrap_socket() ...
Author   Grovespaz
🌐
Iditect
iditect.com › faq › python › attributeerror-39context39-object-has-no-attribute-39wrapsocket39.html
AttributeError: 'Context' object has no attribute 'wrap_socket'
The error message "AttributeError: 'Context' object has no attribute 'wrap_socket'" typically occurs when you are trying to use the wrap_socket function from the ssl module, but the object you are using as a context does not have this attribute.
Find elsewhere
🌐
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
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
🌐
Codehunter
codehunter.tumblr.com › post › 672404164617388032 › attributeerror-context-object-has-no-attribute-wrap-sock
AttributeError: ‘Context’ object has no attribute 'wrap_socket’
January 4, 2022 - 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'
🌐
Python
docs.python.org › 3 › library › ssl.html
ssl — TLS/SSL wrapper for socket objects — Python 3.14.4 ...
Instances of SSLSocket must be created using the SSLContext.wrap_socket() method. The helper function create_default_context() returns a new context with secure default settings.
🌐
YouTube
youtube.com › hey delphi
PYTHON : AttributeError: 'Context' object has no attribute 'wrap_socket' - YouTube
PYTHON : AttributeError: 'Context' object has no attribute 'wrap_socket'To Access My Live Chat Page, On Google, Search for "hows tech developer connect"As pr...
Published   May 28, 2023
Views   39
🌐
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'
🌐
Ubuntu
bugs.launchpad.net › bugs › 1965280
Bug #1965280 “rbd-target-api will not start AttributeError: 'Con...” : Bugs : ceph-iscsi package : Ubuntu
python3/ dist-packages/ werkzeug/ serving. py", line 708, in __init__ self.socket = ssl_context. wrap_socket( self.socket, server_side=True) AttributeError: 'Context' object has no attribute 'wrap_socket' Reported upstream here: https:/ /github. com/ceph/ ceph-iscsi/ issues/ 255 ·
🌐
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
🌐
Trac Project
trac.edgewall.org › ticket › 13749
#13749 (Remove the ssl.wrap_socket() function, deprecated in Python 3.7) – The Trac Project
Use ssl.SSLContext.wrap_socket instead of ssl.wrap_socket removed in Python 3.12 · ​https://docs.python.org/3/whatsnew/3.12.html#ssl
🌐
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.