0

I've been using a Python script for a couple of years without a problem on Xubuntu 20.04, now on 24.04, I’m getting errors connecting to the MySQL server on the same machine.

Relevant code:

import requests
import datetime
import json
from urllib.parse import urlencode, quote_plus
from time import sleep
import mysql.connector

def connectDB():
  return mysql.connector.connect(
    host="localhost",
    user="myuser",
    passwd="mypass",
    database="HomeManagement",
    auth_plugin='mysql_native_password'
  )

timeNow = datetime.datetime.now().replace(microsecond=0, second=0)
print(timeNow)
mydb = connectDB()

Errors:

2024-05-18 19:32:00 Traceback (most recent call last):   File "/usr/local/bin/test.py", line 19, in <module>     mydb = connectDB()            ^^^^^^^^^^^   File "/usr/local/bin/test.py", line 9, in connectDB     return mysql.connector.connect(            ^^^^^^^^^^^^^^^^^^^^^^^^   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' 

Searching around, it seems like its due some change in python 3.12, but I can’t quite pin it down.

Have tried using pymsql but get:

pymysql.err.OperationalError: (2003, "Can't connect to MySQL server on 'localhost' ([Errno 2] No such file or directory)")
2
  • wrap_socket is removed in python 3.12: docs.python.org/3.12/whatsnew/3.12.html#ssl Is there a newer version of the pymysql or mysql package that supports 3.12? Commented May 18, 2024 at 11:12
  • Take a look at Connector/Python Versions to check that you have compatible versions. Commented May 18, 2024 at 11:29

1 Answer 1

1

I faced same problem with Python 3.12 , xampp (php 7.3) then I do "pip uninstall mysql-connector-python"

then again install "pip install mysql-connector-python==8.0.21"

and now its working fine. NOTE:: directly pip install mysql-connector-python is installing about 9 version, so its not working, thats why I uninstall 9 and install 8.0.21 version.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.