The module-level ssl.wrap_socket() was marked as deprecated in Python 3.7 and fully removed in Python 3.12. Programs should create a SSLContext using ssl.create_default_context() and use the context instance's .wrap_socket() method.

In other words, your mysql.connector has not been updated for Python 3.12 compatibility. According to MySQL docs you need mysql.connector version >=8.2.0 for Python 3.12.

You might have better luck using the MySQLdb module, which is available via pip as the "mysqlclient" package. It uses the same C libraries (libmysqlclient or libmariadbclient) and supports TLS.

Answer from grawity on Stack Overflow
🌐
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
🌐
Anvil
anvil.works › show and tell
Anvil-uplink for Python >= 3.12 Solves AttributeError: module 'ssl' has no attribute 'wrap_socket' - #3 by ianb - Show and Tell - Anvil Community Forum
June 19, 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…
Discussions

AttributeError: module 'ssl' has no attribute 'wrap_socket'
Main import.py has the code import eventlet It seems like Eventlet fails with AttributeError: module 'ssl' has no attribute 'wrap_socket'. This happens because of a change in Python. From What's ne... More on github.com
🌐 github.com
1
November 11, 2023
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
Arduino_iot_cloud Python Module issues - 23:35:35.538 Connection failed module 'ssl' has no attribute 'wrap_socket', retrying after 1.0s
Trying to do this example but getting the errors: `23:35:35.538 Connection failed module 'ssl' has no attribute 'wrap_socket', retrying after 1.0s C:\Python312\Lib\site-packages\cbor2\decoder.py:7: UserWarning: The cbor.decoder module has been deprecated. Instead import everything directly ... More on forum.arduino.cc
🌐 forum.arduino.cc
0
0
January 14, 2024
[Python 3.12] AttributeError: module 'ssl' has no attribute 'wrap_socket'
Hello, Fedora is rebuilding all Python packages with upcoming Python 3.12. Eventlet fails with AttributeError: module 'ssl' has no attribute 'wrap_socket'. This happens because of a change in Pytho... More on github.com
🌐 github.com
6
April 3, 2023
🌐
The Mail Archive
mail-archive.com › debian-bugs-dist@lists.debian.org › msg1985332.html
Bug#1075997: pagekite: Fail with python 3.12 (AttributeError: module 'ssl' has no attribute 'wrap_socket')
diff --git a/sockschain/__init__.py b/sockschain/__init__.py index 0849fdf..0794d8d 100755 --- a/sockschain/__init__.py +++ b/sockschain/__init__.py @@ -196,23 +196,23 @@ except ImportError: verify_names=None): if DEBUG: DEBUG('*** TLS is provided by native Python ssl') reqs = (verify_names and ssl.CERT_REQUIRED or ssl.CERT_NONE) + + context = ssl.SSLContext(protocol=ctx.method) + context.verify_mode = reqs + context.load_verify_locations(cafile=ctx.ca_certs) + if ctx.certchain_file: + context.load_cert_chain(certfile=ctx.certchain_file, + keyfile=ctx.privatekey_file) + try: - fd = ssl.wrap_so
🌐
GitHub
github.com › Siyuanw › kinesis › issues › 18
AttributeError: module 'ssl' has no attribute 'wrap_socket' · Issue #18 · Siyuanw/kinesis
November 11, 2023 - Main import.py has the code import eventlet It seems like Eventlet fails with AttributeError: module 'ssl' has no attribute 'wrap_socket'. This happens because of a change in Python. From What's new: Remove the ssl.wrap_socket() function...
Author   kneeroo
🌐
Arduino Forum
forum.arduino.cc › development tools › cloud iot
Arduino_iot_cloud Python Module issues - 23:35:35.538 Connection failed module 'ssl' has no attribute 'wrap_socket', retrying after 1.0s - Cloud IoT - Arduino Forum
January 14, 2024 - Trying to do this example but getting the errors: `23:35:35.538 Connection failed module 'ssl' has no attribute 'wrap_socket', retrying after 1.0s C:\Python312\Lib\site-packages\cbor2\decoder.py:7: UserWarning: The cbor.decoder module has been deprecated. Instead import everything directly ...
🌐
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 - Hello, Fedora is rebuilding all Python packages with upcoming Python 3.12. Eventlet fails with AttributeError: module 'ssl' has no attribute 'wrap_socket'. This happens because of a change in Python. From What's new: Remove the ssl.wrap_...
Author   hrnciar
🌐
Anvil
anvil.works › anvil q&a
Anvil uplink SSL error - Anvil Q&A - Anvil Community Forum
February 29, 2024 - ", line 1, in File "/home/user/src/anvil/venv/lib64/python3.12/site-packages/anvil/server.py", line 359, in connect _get_connection() ...
Find elsewhere
🌐
GitHub
github.com › eventlet › eventlet › issues › 914
module 'ssl' has no attribute 'wrap_socket' · Issue #914
February 11, 2024 - Is there any solution to use counterfit without any error in python version 3.12.2? AttributeError: module 'ssl' has no attribute 'wrap_socket'#914
Author   mahabubamou12
🌐
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 - If you’ve encountered the error AttributeError: module 'ssl' has no attribute 'wrap_socket' while using pyVmomi with Python 3.12, you’re not alone. This error happens due to a change in how Python handles SSL sockets starting from Python 3.7, ...
🌐
Anvil
anvil.works › anvil q&a
Uplink error: module ‘ssl’ has no attribute ‘wrap_socket’ - Anvil Q&A - Anvil Community Forum
March 21, 2024 - Hi All, To set the uplink (I folloewed all the steps indicated in the forum) i get this error: $ C:/Users/chikh/AppData/Local/Programs/Python/Python312/python.exe c:/Users/chikh/uplink/page.py Connecting to wss://anvil…
🌐
GitHub
github.com › zyn3rgy › LdapRelayScan › pull › 33
Solving "ERROR: module 'ssl' has no attribute 'wrap_socket'" when using Python3.12 by 7own · Pull Request #33 · zyn3rgy/LdapRelayScan
Changing old ssl.wrap_socket to newest ssl.SSLContext for Python3.12 compatibility. Before: ~Checking DCs for LDAP NTLM relay protections~ ...
Author   zyn3rgy
🌐
GitHub
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. The function neither sends a SNI TLS extension nor validates server hostname.
Author   ekrichbaum
🌐
Python
docs.python.org › ja › 3.7 › library › ssl.html
ssl --- ソケットオブジェクトに対する TLS/SSL ラッパー — Python 3.7.17 ドキュメント
Since Python 3.2 and 2.7.9, it is recommended to use the SSLContext.wrap_socket() of an SSLContext instance to wrap sockets as SSLSocket objects. The helper functions create_default_context() returns a new context with secure default settings.
🌐
Ubuntu
bugs.launchpad.net › bugs › 2065876
Bug #2065876 “module 'ssl' has no attribute 'wrap_socket'” : Bugs : python-pyvmomi package : Ubuntu
May 16, 2024 - "I cannot geht Ansible Modules from community.vmware to work because of module 'ssl' has no attribute 'wrap_socket'"
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.

🌐
Latenode
community.latenode.com › other questions › mysql
Python 3.12.3 MySQL Connection Error: ssl module missing wrap_socket attribute - MySQL - Latenode Official Community
July 23, 2025 - System Info: OS: Linux Mint 22.1 Cinnamon IDE: VS Code Python: 3.12.3 I’m getting frustrated with this MySQL connection issue. Everything was working fine before, but now I keep getting this error: AttributeError: module 'ssl' has no attribute 'wrap_socket' I was following a MySQL tutorial ...
🌐
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.

🌐
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...
🌐
GitHub
github.com › xmpppy › xmpppy › pull › 70
Fixes AttributeError: module 'ssl' has no attribute 'wrap_socket' by juanvalino · Pull Request #70 · xmpppy/xmpppy
But the xmpppy library uses the top-level wrap_socket function, which got removed in Python 3.12; that one never did certificate validation.
Author   xmpppy