삽질/개발,엔지니어링

pymysql.err.InternalError: Packet sequence number wrong - got 1 expected 0

maengis 2022. 8. 23. 14:04
  File ".../python3.7/lib/python3.7/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

 

웹서버를 추가한 뒤, 특정 DB서버에 접근하면 위 오류가 발생했다.

찾아보니 pymysql의 threadsafe가 1이라서 발생한다고 나왔고, https://peps.python.org/pep-0249/#threadsafety 문서를 읽어보니 뭐 그럴 수도 있겠다 싶었는데, 동일한 코드가 다른 웹서버 세 곳에서는 잘 돌아갔다.

 

from threading import RLock으로 쓰레드 락을 걸어도 처리가 안 되었고, 기존 웹서버들은 pymysql 버전이 0.9.3이고, 문제가 발생한 웹서버는 1.0.2라서 버전 문제인가 싶어서 다운그레이드를 했음에도 동일한 현상이 나왔다. 그러다가 이게 뭔가 싶어서 구글링을 하다가 찾았다.

 

https://stackoverflow.com/questions/51235999/pymysql-err-internalerror-packet-sequence-number-wrong-got-45-expected-0

 

pymysql.err.InternalError: Packet sequence number wrong - got 45 expected 0

I am trying to connect to mysql database via pymysql. Everything works when I SSH into the database via terminal. So, that information is correct. However, when I put the same information in using

stackoverflow.com

 

DB서버도 마스터-슬레이브로 나눠져 있었는데, 마스터에만 접근 권한을 줬었다. 확인해보니 막상 실제로 접근하는 슬레이브에는 권한이 없음...

 

grant SELECT on DB명.* to '계정명'@'IP' identified by '비밀번호' with grant option;
flush privileges;

 

pymysql의 오류 메시지는 정확하지 않다. 방화벽만 접근 되게 해놓고 막상 권한 안 넣었을줄은 몰랐다. 해당 포트 접근해보고 알았음.

# curl -v telnet://서버주소:포트
* About to connect() to 서버주소 port 포트 (#0)
*   Trying 서버IP...
* Connected to 서버주소 (서버IP) port 포트 (#0)
* RCVD IAC 106

* Closing connection 0
IHost '접근서버IP' is not allowed to connect to this MariaDB serve
반응형