'Exception ignored in: <function BaseMySQLSocket.__del__ at 0x000002B15E76E5E0>
I have this strange error in my code, it started to show just like that - no changes in the code.
The same code is working with no problems when I run it from pythonanywhere account, so it's something with my machine I guess. Here's the code:
mydb = mysql.connector.connect(
host='localhost',
user='root',
database='testdb'
)
mycursor = mydb.cursor()
mycursor.execute("SELECT * FROM mytable")
db_result = mycursor.fetchall()
full error:
Exception ignored in: <function BaseMySQLSocket.__del__ at 0x000002B15E76E5E0>
Traceback (most recent call last):
File "C:\Users\user\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\mysql\connector\network.py", line 149, in
__del__
File "C:\Users\user\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\mysql\connector\network.py", line 137, in
shutdown
TypeError: catching classes that do not inherit from BaseException is not allowed
I've reinstalled python-mysql package, tried to upgrade it - no result.
Solution 1:[1]
For me, I got this error in combination with the Pillow (PIL) library: I have not found a solution but I have found that if I do not use image.show() then the error does not occur.
Here's my full code to replicate the error:
import mysql.connector
import PIL.Image
conn = mysql.connector.connect(
host="example.com",
user="root",
password="password",
database="example_database")
mycursor = conn.cursor()
mycursor.execute(f"SELECT id FROM example_table LIMIT 1")
image = PIL.Image.open("test.jpg")
image.show()
mycursor.close()
conn.close()
Gives the error:
Traceback (most recent call last):
File "C:\Users\Michael\Anaconda3\lib\site-packages\mysql\connector\network.py", line 149, in __del__
File "C:\Users\Michael\Anaconda3\lib\site-packages\mysql\connector\network.py", line 137, in shutdown
TypeError: catching classes that do not inherit from BaseException is not allowed
To avoid the error, remove the line image.show().
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
