Packet sequence number wrong

See original GitHub issue

I’ve been using PyMySQL 0.6.6 for a while now with no issues. However after updating to 0.7.1, I’m getting this error a lot, and PyMySQL has become completely unusable for me because of it.

  File "/usr/local/lib/python3.4/dist-packages/pymysql/cursors.py", line 146, in execute
    result = self._query(query)
  File "/usr/local/lib/python3.4/dist-packages/pymysql/cursors.py", line 296, in _query
    conn.query(q)
  File "/usr/local/lib/python3.4/dist-packages/pymysql/connections.py", line 819, in query
    self._affected_rows = self._read_query_result(unbuffered=unbuffered)
  File "/usr/local/lib/python3.4/dist-packages/pymysql/connections.py", line 1001, in _read_query_result
    result.read()
  File "/usr/local/lib/python3.4/dist-packages/pymysql/connections.py", line 1285, in read
    first_packet = self.connection._read_packet()
  File "/usr/local/lib/python3.4/dist-packages/pymysql/connections.py", line 952, in _read_packet
    (packet_number, self._next_seq_id))
pymysql.err.InternalError: Packet sequence number wrong - got 101 expected 1

The packet numbers vary, but I’m getting this for every query now, no matter how simple. Things will work as expected for a few minutes after starting my script, but soon after these errors will begin appearing and no queries will work anymore.

I’m not sure if there’s something I can do to resolve this in my script (some changes made in newer versions that I need to accommodate for) or if I should just figure out how to install the older version as a temporary solution. As it is now, this is a complete showstopper for me.

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:16 (5 by maintainers)

github_iconTop GitHub Comments

12reactions
methanecommented, Jan 26, 2016

See https://www.python.org/dev/peps/pep-0249/#threadsafety

PyMySQL’s threadsafety is 1.

7reactions
MyJoiTcommented, Sep 15, 2018

@methane

SQLAlchemy also has this problem in multithread if you use one session,like this:

# base.py
engine = create_engine(
    get_db_str(),
    echo=False,
    pool_recycle=300,
    poolclass=QueuePool,
    pool_size=10,
    max_overflow=10,
    pool_timeout=30,
    listeners=[Reconnect()]
)

Session = sessionmaker(bind=engine)

# user1.py
from .base import Session
session1 = Session()
session1.query

# user2.py
from .base import Session
session2 = Session()
session2.query

I use ab command send 1000 requests to system. System raise that exception after some requests.

Read more comments on GitHub >

github_iconTop Results From Across the Web

pymysql.err.InternalError: Packet sequence number wrong
InternalError ) Packet sequence number wrong - got 1 expected 0. The issue for me was my IP was being blocked by the...
Read more >
Packet sequence number wrong (PyMySQL driver or…?)
I'm using SQLAlchemy (1.1.13) and SQLAlchemy-Utils (0.32.14) in the context of a Pyramid (1.9.1) web-browser, PyMySQL (0.7.11) as a driver, and mysql 5.6.3....
Read more >
401 with message "Packet sequence number wrong..."
When I was installed DevStack (with Skyline), I had login successfuly. After a while (about 6~12 hours later), When I try to login...
Read more >
pymysql.err.InternalError: Packet sequence number wrong
Just a warning that this error is a general database connectivity error that is caused for a multitude of reasons.
Read more >
Poller error. Could not connect to MySQL database. Packet ...
2021-10-04 09:14:09,972 :: CRITICAL :: ERROR: Could not connect to MySQL database! Packet sequence number wrong - got 1 expected 0
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found