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.

Answer from rfc on askubuntu.com
🌐
Ubuntu
bugs.launchpad.net › bugs › 2069026
Bug #2069026 “mysql-connector-python is broken on Ubuntu 24.04: ...” : Bugs : mysql-connector-python package : Ubuntu
py", line 427, in switch_to_ssl self.sock = ssl.wrap_socket( ^^^^^ ^^^^^^^ ^^^ AttributeError: module 'ssl' has no attribute 'wrap_socket' Revision history for this message · Status changed to 'Confirmed' because the bug affects multiple users. Revision history for this message ·
🌐
Stack Overflow
stackoverflow.com › questions › 78624749 › python-mysql-connector-wrap-socket
Python MySQL connector wrap_socket - Stack Overflow
The first error makes sense-- wrap_socket() is indeed not a top-level function of ssl but a method of SSLContext; you're right to remove that line.
Discussions

MySQL problem: "Exception has occurred: AttributeError: module 'ssl' has no attribute 'wrap_socket' " on python 3.12.3
Oracle's mysql-connector-python is one of the top 3 worst libraries that I've ever had the displeasure of using. It is coded by amateurs. Older versions even had SQL injection vulnerabilities in the very code that was supposed to defend against such security problems. I've suffered segfaults originating in their code. There are breaking changes in pretty much every version. Their TLS-related code is particularly poor, depending on which of the three or four different MySQL protocol implementations in that library is used. If you have a choice, use literally anything else than this "official" MySQL client library. The SQLAlchemy docs have a list of various client libraries: https://docs.sqlalchemy.org/en/20/dialects/mysql.html#dialect-mysql Edit: I vaguely remember challenges with TLS when connecting to a database on localhost. In one project, I ended up monkeypatching a fix into the mysql-connector. Perhaps it is possible for you to explicitly disable TLS when making the connection? The setting should be ssl_disabled=True, but I'm not sure if it will work for your problem. More on reddit.com
🌐 r/learnpython
4
0
July 30, 2025
[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
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'
Hi, Using secure connection, I am getting an error: AttributeError: module 'ssl' has no attribute 'wrap_socket' I suspect it is due to a change in Python -- see eventlet/eventlet#79... More on github.com
🌐 github.com
6
May 3, 2024
🌐
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 error with Python 3.12: ``` File "/usr/lib/python3/dist-packages/mysql/connector/__init__.py", line 173, in connect return MySQLConnection(*args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/lib/python3/dist-packages/mysql/connector/connection.py", line 102, in __init__ self.connect(**kwargs) File "/usr/lib/python3/dist-packages/mysql/connector/abstracts.py", line 735, in connect self._open_connection() File "/usr/lib/python3/dist-packages/mysql/connector/connection.py", line 250, in _open_connection self._do_auth(self._user, self._password, File "
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.

🌐
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.

🌐
Debian
bugs-devel.debian.org › 1076136
#1076136 - AttributeError: module 'ssl' has no attribute 'wrap_socket' with Python 3.12 - Debian Bug report logs
Subject: AttributeError: module 'ssl' has no attribute 'wrap_socket' with Python 3.12 · Date: Thu, 11 Jul 2024 11:23:13 +0200 · Package: python3-mysql.connector Version: 8.0.15-4 Severity: serious -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA512 After the update to Python 3.12, I can no longer use the mysql.connector.connect function due to this error: File "/usr/lib/python3/dist-packages/mysql/connector/__init__.py", line 173, in connect return MySQLConnection(*args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/lib/python3/dist-packages/mysql/connector/connection.py", line 102, in _
🌐
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
Find elsewhere
🌐
GitHub
github.com › supersaiyanmode › PyWebOSTV › issues › 108
AttributeError: module 'ssl' has no attribute 'wrap_socket' · Issue #108 · supersaiyanmode/PyWebOSTV
May 3, 2024 - Hi, Using secure connection, I am getting an error: AttributeError: module 'ssl' has no attribute 'wrap_socket' I suspect it is due to a change in Python -- see eventlet/eventlet#79...
Author   MarkStoutjesdijk
🌐
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 ...
🌐
Ubuntu
bugs.launchpad.net › bugs › 2065876
Bug #2065876 “module 'ssl' has no attribute 'wrap_socket'” : Bugs : python-pyvmomi package : Ubuntu
May 16, 2024 - mysql.connector supports python versions 3.11, 3.10, 3.9, 3.8, 3.7, (3.6 before 8.0.29), (2.7 and 3.5 before 8.0.24), but NOT version 3.12 which is what ships with noble.
🌐
The Mail Archive
mail-archive.com › debian-bugs-dist@lists.debian.org › msg1979712.html
Bug#1076136: AttributeError: module 'ssl' has no attribute 'wrap_socket' with Python 3.12
July 11, 2024 - After the update to Python 3.12, ...l(ssl_options.get('ca'), File "/usr/lib/python3/dist-packages/mysql/connector/network.py", line 427, in switch_to_ssl self.sock = ssl.wrap_socket( ^^^^^^^^^^^^^^^ AttributeError: module 'ssl' has no attribute 'wrap_socket' It seems that Python ...
🌐
Blunturi
blunturi.org › attributeerror-module-ssl-has-no-attribute-wrap_socket-mysql
attributeerror: module 'ssl' has no attribute 'wrap_socket' mysql
August 24, 2024 - Maintain clear documentation of your MySQL and Python configuration settings. This makes it easier to troubleshoot issues and replicate setups across different environments. A: This error indicates that Python’s SSL module cannot find the “AttributeError: module ‘ssl’ has no attribute ‘wrap_socket’ mysql” attribute, which is essential for enabling SSL/TLS encryption in socket connections.
🌐
The Mail Archive
mail-archive.com › ubuntu-bugs@lists.ubuntu.com › msg6070108.html
[Bug 2065876] Re: module 'ssl' has no attribute 'wrap_socket'
June 11, 2024 - The issue also affects the package python3-mysql.connector: File "/usr/lib/python3/dist-packages/mysql/connector/__init__.py", line 173, in connect return MySQLConnection(*args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/lib/python3/dist-packages/mysql/connector/connection.py", line ...
🌐
A Girl Among Geeks
agirlamonggeeks.com › home › how can i fix the attributeerror: module ‘ssl’ has no attribute ‘wrap_socket’ when connecting to mysql?
How Can I Fix the AttributeError: Module 'ssl' Has No Attribute 'wrap_socket' When Connecting to MySQL?
July 4, 2025 - To resolve the `AttributeError` related to `Wrap_Socket`, follow these steps: Verify Python Version: Ensure your Python installation is up to date and consistent with your codebase. Inspect the SSL Module: Use the Python shell to check available attributes: “`python import ssl dir(ssl) “` ...
🌐
The Mail Archive
mail-archive.com › ubuntu-bugs@lists.ubuntu.com › msg6070112.html
[Bug 2069026] [NEW] mysql-connector-python is broken on Ubuntu 24.04: AttributeError: module 'ssl' has no attribute 'wrap_socket'
Public bug reported: File "/usr/lib/python3/dist-packages/mysql/connector/__init__.py", line 173, in connect return MySQLConnection(*args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/lib/python3/dist-packages/mysql/connector/connection.py", line 102, in __init__ self.connect(**kwargs) File "/usr/lib/python3/dist-packages/mysql/connector/abstracts.py", line 735, in connect self._open_connection() File "/usr/lib/python3/dist-packages/mysql/connector/connection.py", line 250, in _open_connection self._do_auth(self._user, self._password, File "/usr/lib/python3/dist-packages/mysql/connector/connection.py", line 155, in _do_auth self._socket.switch_to_ssl(ssl_options.get('ca'), File "/usr/lib/python3/dist-packages/mysql/connector/network.py", line 427, in switch_to_ssl self.sock = ssl.wrap_socket( ^^^^^^^^^^^^^^^ AttributeError: module 'ssl' has no attribute 'wrap_socket'
🌐
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…
🌐
Ubuntu
bugs.launchpad.net › ubuntu › +source › mysql-connector-python
mysql-connector-python package : Ubuntu - Launchpad Bugs
#2069026 mysql-connector-python is broken on Ubuntu 24.04: AttributeError: module 'ssl' has no attribute 'wrap_socket'
🌐
The Mail Archive
mail-archive.com › ubuntu-bugs@lists.ubuntu.com › msg6098749.html
[Bug 2069026] Re: mysql-connector-python is broken on Ubuntu 24.04: AttributeError: module 'ssl' has no attribute 'wrap_socket'
September 17, 2024 - ssl.wrap_socket was removed from Python. Upstream fix: https://github.com/mysql/mysql-connector- python/commit/22cdd217fc41457a95a3bcc15c0f0bf9def58e1c · -- You received this bug notification because you are a member of Ubuntu Bugs, which is subscribed to Ubuntu. https://bugs.launchpad.net/bugs/2069026 Title: mysql-connector-python is broken on Ubuntu 24.04: AttributeError: module 'ssl' has no attribute 'wrap_socket' To manage notifications about this bug go to: https://bugs.launchpad.net/ubuntu/+source/mysql-connector-python/+bug/2069026/+subscriptions -- ubuntu-bugs mailing list ubuntu-bugs@lists.ubuntu.com https://lists.ubuntu.com/mailman/listinfo/ubuntu-bugs