Python - pymysql.err.Error: Already closed
Hi,
pymysql.err.InterfaceError: (0, '') often occurs when working with pymysql after updating Python.
I use the same con connection call in the whole script as follows:
and then I just call everywhere
The whole error:
Thanks
Hi,
so you need to call everywhere before using with con and a new connection using con:
pymysql.err.InterfaceError: (0, '') often occurs when working with pymysql after updating Python.
I use the same con connection call in the whole script as follows:
con = mysql.connect(**config)
and then I just call everywhere
with con:
The whole error:
Traceback (most recent call last):
File "/var/script45.py", line 387, in fillerLoop
cur.execute(sql)
File "/usr/local/lib/python3.8/dist-packages/pymysql/cursors.py", line 148, in execute
result = self._query(query)
File "/usr/local/lib/python3.8/dist-packages/pymysql/cursors.py", line 310, in _query
conn.query(q)
File "/usr/local/lib/python3.8/dist-packages/pymysql/connections.py", line 547, in query
self._execute_command(COMMAND.COM_QUERY, sql)
File "/usr/local/lib/python3.8/dist-packages/pymysql/connections.py", line 793, in _execute_command
raise err.InterfaceError(0, "")
pymysql.err.InterfaceError: (0, '')
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/var/script45.py", line 391, in fillerLoop
print("-----------")
File "/usr/local/lib/python3.8/dist-packages/pymysql/connections.py", line 360, in __exit__
self.close()
File "/usr/local/lib/python3.8/dist-packages/pymysql/connections.py", line 404, in close
raise err.Error("Already closed")
pymysql.err.Error: Already closed
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/var/script45.py", line 423, in
object.fillerLoop()
File "/var/script45.py", line 408, in fillerLoop
sys.exit("Program ukoncen!")
File "/usr/local/lib/python3.8/dist-packages/pymysql/connections.py", line 360, in __exit__
self.close()
File "/usr/local/lib/python3.8/dist-packages/pymysql/connections.py", line 404, in close
raise err.Error("Already closed")
Thanks
REPLY
Hi,
so you need to call everywhere before using with con and a new connection using con:
con = mysql.connect(**config)
with con:
xxxxxxxx