Merhaba,
Bir bilgisayarda client olarak websocket çalıştırıyorum. Farklı makinede ubuntu üzerinde de python script ile websocket server çalışıyor. Client’ten gelen verileri server’da python ile yakalayıp gelen verileri mySQL veritabanına INSERT ediyorum.
Sistem çalışıyor fakat tam 2 dakika sonra aşağıdaki hatayı alıyorum her seferinde ve veri kaydetmeyi durduruyor.
Hata mesajı;
Error in connection handler
Traceback (most recent call last):
File "/home/burp/PycharmProjects/pythonProject/venv/lib/python3.8/site-packages/mysql/connector/connection_cext.py", line 506, in cmd_query
self._cmysql.query(query,
_mysql_connector.MySQLInterfaceError: Lost connection to MySQL server during query
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/burp/PycharmProjects/pythonProject/venv/lib/python3.8/site-packages/websockets/server.py", line 191, in handler
await self.ws_handler(self, path)
File "main.py", line 19, in get_infos
mycursor.execute(sql)
File "/home/burp/PycharmProjects/pythonProject/venv/lib/python3.8/site-packages/mysql/connector/cursor_cext.py", line 269, in execute
result = self._cnx.cmd_query(stmt, raw=self._raw,
File "/home/burp/PycharmProjects/pythonProject/venv/lib/python3.8/site-packages/mysql/connector/connection_cext.py", line 510, in cmd_query
raise errors.get_mysql_exception(exc.errno, msg=exc.msg,
mysql.connector.errors.OperationalError: 2013 (HY000): Lost connection to MySQL server during query
Websocket py ve INSERT scriptim ;
import asyncio
import websockets
import mysql.connector
mydb = mysql.connector.connect(
host="db.ipim",
user="pyu",
password="pass123456",
database="pyn"
)
mycursor = mydb.cursor()
async def get_infos(websocket, path):
async for message in websocket:
sql = """INSERT INTO tablom (veriler)
VALUES ('[%s]')""" % message
mycursor.execute(sql)
start_server = websockets.serve(get_infos, "ip.adre.sim", 9090)
asyncio.get_event_loop().run_until_complete(start_server)
asyncio.get_event_loop().run_forever()
Web üzerinde araştırdım max_allowed_package ile ilgili olabileceği tartışılmış fakat sunucumun ilgili değeri zaten çok yüksek. Ayrıca INSERT edilmesi gereken veri en fazla 40 kb.
Yardımlarınızı bekliyorum teşekkürler.