在MariaDb中获取以下错误及其导致的超时问题:通过删除skip-name-resolve、向user@localhost授予权限以及在pyton create_engine中使用pool_pre_ping = True和pool_recycle=3600对其进行调试,但似乎没有解决问题。MariaDb版本为10.4.20,Python版本为3.9。它也不是多线程应用程序。任何有关解决调试此问题的指针都将有所帮助。
这是正在创建的连接:
db_connection_str = 'mysql+pymysql://root:root@localhost:3306/collection'
sql_engine = create_engine(db_connection_str,pool_pre_ping=True pool_recycle=3600)
def get_engine():
engine = create_engine(db_connection_str, pool_pre_ping=True,pool_recycle=3600)
return engine
引擎用于获取'sql_engine.connect()'
形式的连接或与'Session = sessionmaker(bind=sql_engine) session = Session()'
一起使用错误:'''
(Background on this error at: https://sqlalche.me/e/14/2j85)
Traceback (most recent call last):
File "D:\Python\lib\site-packages\sqlalchemy\engine\base.py", line 3212, in _wrap_pool_connect
return fn()
File "D:\Python\lib\site-packages\sqlalchemy\pool\base.py", line 307, in connect
return _ConnectionFairy._checkout(self)
File "D:\Python\lib\site-packages\sqlalchemy\pool\base.py", line 767, in _checkout
fairy = _ConnectionRecord.checkout(pool)
File "D:\Python\lib\site-packages\sqlalchemy\pool\base.py", line 425, in checkout
rec = pool._do_get()
File "D:\Python\lib\site-packages\sqlalchemy\pool\impl.py", line 146, in _do_get
self._dec_overflow()
File "D:\Python\lib\site-packages\sqlalchemy\util\langhelpers.py", line 72, in __exit__
with_traceback=exc_tb,
File "D:\Python\lib\site-packages\sqlalchemy\util\compat.py", line 207, in raise_
raise exception
File "D:\Python\lib\site-packages\sqlalchemy\pool\impl.py", line 143, in _do_get
return self._create_connection()
File "D:\Python\lib\site-packages\sqlalchemy\pool\base.py", line 253, in _create_connection
return _ConnectionRecord(self)
File "D:\Python\lib\site-packages\sqlalchemy\pool\base.py", line 368, in __init__
self.__connect()
File "D:\Python\lib\site-packages\sqlalchemy\pool\base.py", line 611, in __connect
pool.logger.debug("Error on connect(): %s", e)
File "D:\Python\lib\site-packages\sqlalchemy\util\langhelpers.py", line 72, in __exit__
with_traceback=exc_tb,
File "D:\Python\lib\site-packages\sqlalchemy\util\compat.py", line 207, in raise_
raise exception
File "D:\Python\lib\site-packages\sqlalchemy\pool\base.py", line 605, in __connect
connection = pool._invoke_creator(self)
File "D:\Python\lib\site-packages\sqlalchemy\engine\create.py", line 578, in connect
return dialect.connect(*cargs,**cparams)
File "D:\Python\lib\site-packages\sqlalchemy\engine\default.py", line 584, in connect
return self.dbapi.connect(*cargs,**cparams)
File "D:\Python\lib\site-packages\pymysql\connections.py", line 353, in __init__
self.connect()
File "D:\Python\lib\site-packages\pymysql\connections.py", line 632, in connect
self._get_server_information()
File "D:\Python\lib\site-packages\pymysql\connections.py", line 1055, in _get_server_information
packet = self._read_packet()
File "D:\Python\lib\site-packages\pymysql\connections.py", line 707, in _read_packet
% (packet_number, self._next_seq_id)
pymysql.err.InternalError: Packet sequence number wrong - got 1 expected 0
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "C:/xampp/htdocs/prod/collectionaccounting/bot_run.py", line 142, in <module>
main()
File "C:/xampp/htdocs/prod/collectionaccounting/bot_run.py", line 138, in main
BotRunLogger.log(level='success', msg='Bot Run completed successfully')
File "C:\xampp\htdocs\prod\collectionaccounting\AppLogger\BotRunLogger.py", line 12, in log
settings = config.get_settings()
File "C:\xampp\htdocs\prod\collectionaccounting\Api\config.py", line 112, in get_settings
result = session.query(Settings).all()
File "D:\Python\lib\site-packages\sqlalchemy\orm\query.py", line 2712, in all
return self._iter().all()
File "D:\Python\lib\site-packages\sqlalchemy\orm\query.py", line 2850, in _iter
execution_options={"_sa_orm_load_options": self.load_options},
File "D:\Python\lib\site-packages\sqlalchemy\orm\session.py", line 1688, in execute
conn = self._connection_for_bind(bind)
File "D:\Python\lib\site-packages\sqlalchemy\orm\session.py", line 1530, in _connection_for_bind
engine, execution_options
File "D:\Python\lib\site-packages\sqlalchemy\orm\session.py", line 747, in _connection_for_bind
conn = bind.connect()
File "D:\Python\lib\site-packages\sqlalchemy\engine\base.py", line 3166, in connect
return self._connection_cls(self, close_with_result=close_with_result)
File "D:\Python\lib\site-packages\sqlalchemy\engine\base.py", line 96, in __init__
else engine.raw_connection()
File "D:\Python\lib\site-packages\sqlalchemy\engine\base.py", line 3245, in raw_connection
return self._wrap_pool_connect(self.pool.connect, _connection)
File "D:\Python\lib\site-packages\sqlalchemy\engine\base.py", line 3216, in _wrap_pool_connect
e, dialect, self
File "D:\Python\lib\site-packages\sqlalchemy\engine\base.py", line 2070, in _handle_dbapi_exception_noconnection
sqlalchemy_exception, with_traceback=exc_info[2], from_=e
File "D:\Python\lib\site-packages\sqlalchemy\util\compat.py", line 207, in raise_
raise exception
File "D:\Python\lib\site-packages\sqlalchemy\engine\base.py", line 3212, in _wrap_pool_connect
return fn()
File "D:\Python\lib\site-packages\sqlalchemy\pool\base.py", line 307, in connect
return _ConnectionFairy._checkout(self)
File "D:\Python\lib\site-packages\sqlalchemy\pool\base.py", line 767, in _checkout
fairy = _ConnectionRecord.checkout(pool)
File "D:\Python\lib\site-packages\sqlalchemy\pool\base.py", line 425, in checkout
rec = pool._do_get()
File "D:\Python\lib\site-packages\sqlalchemy\pool\impl.py", line 146, in _do_get
self._dec_overflow()
File "D:\Python\lib\site-packages\sqlalchemy\util\langhelpers.py", line 72, in __exit__
with_traceback=exc_tb,
File "D:\Python\lib\site-packages\sqlalchemy\util\compat.py", line 207, in raise_
raise exception
File "D:\Python\lib\site-packages\sqlalchemy\pool\impl.py", line 143, in _do_get
return self._create_connection()
File "D:\Python\lib\site-packages\sqlalchemy\pool\base.py", line 253, in _create_connection
return _ConnectionRecord(self)
File "D:\Python\lib\site-packages\sqlalchemy\pool\base.py", line 368, in __init__
self.__connect()
File "D:\Python\lib\site-packages\sqlalchemy\pool\base.py", line 611, in __connect
pool.logger.debug("Error on connect(): %s", e)
File "D:\Python\lib\site-packages\sqlalchemy\util\langhelpers.py", line 72, in __exit__
with_traceback=exc_tb,
File "D:\Python\lib\site-packages\sqlalchemy\util\compat.py", line 207, in raise_
raise exception
File "D:\Python\lib\site-packages\sqlalchemy\pool\base.py", line 605, in __connect
connection = pool._invoke_creator(self)
File "D:\Python\lib\site-packages\sqlalchemy\engine\create.py", line 578, in connect
return dialect.connect(*cargs,**cparams)
File "D:\Python\lib\site-packages\sqlalchemy\engine\default.py", line 584, in connect
return self.dbapi.connect(*cargs,**cparams)
File "D:\Python\lib\site-packages\pymysql\connections.py", line 353, in __init__
self.connect()
File "D:\Python\lib\site-packages\pymysql\connections.py", line 632, in connect
self._get_server_information()
File "D:\Python\lib\site-packages\pymysql\connections.py", line 1055, in _get_server_information
packet = self._read_packet()
File "D:\Python\lib\site-packages\pymysql\connections.py", line 707, in _read_packet
% (packet_number, self._next_seq_id)
sqlalchemy.exc.InternalError: (pymysql.err.InternalError) Packet sequence number wrong - got 1 expected 0
(Background on this error at: https://sqlalche.me/e/14/2j85)'''
1条答案
按热度按时间rjee0c151#
在create_engine中使用了poolclass=NullPool。这已修复了这种情况下的数据包序列错误。应用程序不再因数据包序列错误而停止。