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.
python - SSL wrap socket: AttributeError: 'module' object has no attribute 'wrap_socket' - Stack Overflow
Python 3.12.3 MySQL Connection Error: ssl module missing wrap_socket attribute
Anvil-uplink for Python >= 3.12 Solves AttributeError: module 'ssl' has no attribute 'wrap_socket' - Show and Tell - Anvil Community Forum
MySQL problem: "Exception has occurred: AttributeError: module 'ssl' has no attribute 'wrap_socket' " on python 3.12.3
Don't name your script ssl.py, because when you name your script ssl.py and you do import ssl you're importing this same script .
Your script is : ssl.py
When you do an import ssl, it calls itself and that is why you get the AttributeError
Give another name to your script and it should work.
OS: Linux Mint 22.1 CinnamonIDE: VS CodePython 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.