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
🌐
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 - Any package that still uses ssl.wrap_socket() is broken and insecure. The function neither sends a SNI TLS extension nor validates server hostname. Code is subject to CWE-295: Improper Certificate Validation.
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.3 MySQL Connection Error: ssl module missing wrap_socket attribute
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 ... More on community.latenode.com
🌐 community.latenode.com
1
0
July 23, 2025
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
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
🌐
GitHub
github.com › supersaiyanmode › PyWebOSTV › issues › 108
AttributeError: module 'ssl' has no attribute 'wrap_socket' · Issue #108 · supersaiyanmode/PyWebOSTV
May 3, 2024 - AttributeError: module 'ssl' has no attribute 'wrap_socket' I suspect it is due to a change in Python -- see eventlet/eventlet#795. It would be great if you could take a look at this! Reactions are currently unavailable · No one assigned · No labels · No labels ·
Author   MarkStoutjesdijk
🌐
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 - Modify the Code: Find the line where _SocketWrapper is defined, which looks like this: ... Save and Test: Save the changes to the SoapAdapter.py file, then try running your script again. The error should no longer occur, and everything should work as expected. In Python 3.7 and later, the ssl.wrap_socket method was removed in favor of the SSLContext.wrap_socket method, which is now the standard for creating SSL sockets.
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.

🌐
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 ·
🌐
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 ...witch_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' ``` This ...
Find elsewhere
🌐
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 ...
🌐
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.
🌐
Ubuntu
bugs.launchpad.net › bugs › 2065876
Bug #2065876 “module 'ssl' has no attribute 'wrap_socket'” : Bugs : python-pyvmomi package : Ubuntu
May 16, 2024 - Here is an example of the errors you get when using it: An exception occurred during task execution. To see the full traceback, use -vvv. The error was: AttributeError: module 'ssl' has no attribute 'wrap_socket' fatal: [svnipap-0009 -> localhost]: FAILED!
🌐
Python
docs.python.org › 3 › library › ssl.html
ssl — TLS/SSL wrapper for socket objects — Python 3.14.4 ...
Changed in version 3.5: Always allow a server_hostname to be passed, even if OpenSSL does not have SNI. Changed in version 3.6: session argument was added. Changed in version 3.7: The method returns an instance of SSLContext.sslsocket_class instead of hard-coded SSLSocket. ... The return type of SSLContext.wrap_socket(), defaults to SSLSocket. The attribute can be assigned to on instances of SSLContext in order to return a custom subclass of SSLSocket.
🌐
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.
🌐
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
Package: python3-mysql.connector ...witch_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' It seems ...
🌐
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 423, in _real_connect self.do_handshake() File "/usr/lib/python2.7/ssl.py", line 405, in do_handshake self._sslobj.do_handshake() ssl.SSLError: [Errno 1] _ssl.c:510: error:14094410:SSL routines:SSL3_READ_BYTES:sslv3 alert handshake failure import socket import ssl # SET VARIABLES packet, reply = "<packet>SOME_DATA</packet>", "" HOST, PORT = 'www.google.com.hk'
🌐
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.works/uplink Traceback (most recent call last): File “c:\Users\chikh\uplink\page.py”, line 3, in anvil.server.connect(“client_QUJ2CSVLY7ZKI46Q4F3ZCCLK-RPB3TV5SAQP7CSVA”) File “C:\Users\chikh\AppData\Local\Programs\Python\Python312\Lib\site-packages\anvil\server.py”, line 35...
🌐
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
🌐
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, ...witch_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' It seems ...