环境:Python 3.8.5

在使用pymysql去数据库查询数据时,出现了如下错误:

Exception ignored in: <function MysqlPoolClient.__del__ at 0x000001107810DC10>
Traceback (most recent call last):File "E:\test\work\myspider\utils\mysql_pool.py", line 39, in __del__self.dispose()File "E:\test\work\myspider\utils\mysql_pool.py", line 206, in disposeself.end('commit')File "E:\test\work\myspider\utils\mysql_pool.py", line 196, in endself._conn.commit()File "E:\test\venv1\lib\site-packages\dbutils\steady_db.py", line 435, in commitraise error  # re-raise the original errorFile "E:\test\venv1\lib\site-packages\dbutils\steady_db.py", line 426, in commitself._con.commit()File "C:\Users\admin\AppData\Roaming\Python\Python38\site-packages\pymysql\connections.py", line 422, in commitself._read_ok_packet()File "C:\Users\admin\AppData\Roaming\Python\Python38\site-packages\pymysql\connections.py", line 396, in _read_ok_packetpkt = self._read_packet()File "C:\Users\admin\AppData\Roaming\Python\Python38\site-packages\pymysql\connections.py", line 658, in _read_packetraise err.InternalError(
pymysql.err.InternalError: Packet sequence number wrong - got 5 expected 1

最开始查找的相关资料,都是说多线程未加锁导致类似问题的出现,例如:python pymysql 多线程 读写数据库 报错 Packet sequence number wrong

但实际上,mysql_pool.py是基于pymysql封装的模块,已经注意了多线程锁的问题,所以考虑实际问题不是因为未加锁。

重新使用traceback模块打印异常,发现了如下错误:

Traceback (most recent call last):File "E:/test/work/myspider/spider_files/tianyancha_new/mysql_to_es.py", line 52, in get_one_from_companyresult = client.getOne(sql)File "E:\test\work\myspider\utils\mysql_pool.py", line 88, in getOnecount = self._cursor.execute(sql)File "E:\test\venv1\lib\site-packages\dbutils\steady_db.py", line 598, in tough_methodresult = method(*args, **kwargs)  # try to executeFile "C:\Users\admin\AppData\Roaming\Python\Python38\site-packages\pymysql\cursors.py", line 163, in executeresult = self._query(query)File "C:\Users\admin\AppData\Roaming\Python\Python38\site-packages\pymysql\cursors.py", line 321, in _queryconn.query(q)File "C:\Users\admin\AppData\Roaming\Python\Python38\site-packages\pymysql\connections.py", line 505, in queryself._affected_rows = self._read_query_result(unbuffered=unbuffered)File "C:\Users\admin\AppData\Roaming\Python\Python38\site-packages\pymysql\connections.py", line 724, in _read_query_resultresult.read()File "C:\Users\admin\AppData\Roaming\Python\Python38\site-packages\pymysql\connections.py", line 1076, in readself._read_result_packet(first_packet)File "C:\Users\admin\AppData\Roaming\Python\Python38\site-packages\pymysql\connections.py", line 1146, in _read_result_packetself._read_rowdata_packet()File "C:\Users\admin\AppData\Roaming\Python\Python38\site-packages\pymysql\connections.py", line 1184, in _read_rowdata_packetrows.append(self._read_row_from_packet(packet))File "C:\Users\admin\AppData\Roaming\Python\Python38\site-packages\pymysql\connections.py", line 1203, in _read_row_from_packetdata = converter(data)
TypeError: conversion from bytes to Decimal is not supported

看见“Decimal”想起来,要查询的数据中,有个字段是Decimal类型,然后继续查找相关资料:

pymysql TypeError: conversion from bytes to Decimal is not supported,这位大佬直接去把pymysql源码做了修改,应该也能解决问题(未实验)

后来参考了这个:python-Django錯誤:不支持從字節到十進位的轉換,大体意思是,由于use_unicode设置为False导致。

use_unicode是连接mysql时设置的一个参数,在python3中,该参数默认是True,但是在封装的mysql_pool.py中,use_unicode设置的为False,所以产生了上面的错误。重新将use_unicode改为True,即可避免上述问题的出现了。

参考:PyMySQL 官方文档

另外,当use_unicode设置为False时,查询结果里的文本对象都是字节类型;设置为True后,获取到的文本对象是字符串类型的数据。

使用pymysql报错:pymysql.err.InternalError: Packet sequence number wrong - got 5 expected 1相关推荐

  1. 转载|pymysql.err.InternalError: Packet sequence number wrong - got 45 expected 0

    原文链接:https://www.cnblogs.com/heiao10duan/p/9373237.html 原因: 使用了多线程,多线程共享了同一个数据库连接,但每个execute前没有加上互斥锁 ...

  2. sqlalchemy.exc.InternalError: (pymysql.err.InternalError) Packet sequence number wrong - got 40 expe

    sqlalchemy.exc.InternalError: (pymysql.err.InternalError) Packet sequence number wrong - got 40 expe ...

  3. python pymysql 多线程 读写数据库 报错 Packet sequence number wrong

    多线程连接数据,提交增改查请求,爆出Packet sequence number wrong - got 7 expected 2(数据包序列号错误) 原因:这是因为多线程共享了同一个数据库连接,但每 ...

  4. python pymysql emoji表情插入mysql数据库异常记录报错 pymysql.err.InternalError

    在数据库存储微信小程序用户昵称时候,发现用户昵称使用emoji表情时候就存不了数据库中间报错 pymysql.err.InternalError: (1366, "Incorrect str ...

  5. 数据导入报错:Got a packet bigger than‘max_allowed_packet’bytes的问题

    2019独角兽企业重金招聘Python工程师标准>>> 数据导入报错:Got a packet bigger than'max_allowed_packet'bytes的问题 2个解 ...

  6. npm install 报错:ERR! code EINTEGRITY 解决方案

    npm install 报错:ERR! code EINTEGRITY 解决方案 参考文章: (1)npm install 报错:ERR! code EINTEGRITY 解决方案 (2)https: ...

  7. mysql数据库报错1146_关于MySQL报错:[ERR] 1146

    最近因为电脑重装了系统,导致自己原本的数据库呗覆盖,需要重新重新安装数据库,但是由于我之前数据库版本是mysql 5.0.22,版本太低,所以小编决定安装mysql 5.7.23版本的,一开始没什么问 ...

  8. Vue项目 报错TypeError [ERR INVALID ARG TYPE]: The “path“ argument must be of type string

    # Vue项目 报错TypeError [ERR INVALID ARG TYPE]: The "path" argument must be of type string 卡了半 ...

  9. npm install报错 npm ERR,code ERESOLVE npm ERR,ERESOLVE unable to resolve dependency tree

    文章目录 前言 问题分析 解决方法 转载于 前言 在下载npm时报错npm ERR! code ERESOLVE npm ERR! ERESOLEVE unable to resolve depend ...

最新文章

  1. 皮一皮:说好的一起守护光和未来呢...
  2. SQLServer数据库自增长标识列的更新修改操作
  3. Github Clone to local files
  4. 发牌一周年 国内5G发展如何?
  5. 各种乐器与人声的频率特性说明
  6. Java示例:如何执行进程并读取输出
  7. 计算机考试操作步骤,计算机考试操作步骤(精).doc
  8. SVN忽略提交文件设置
  9. 两个pdf合并成一个pdf
  10. HTML干净的网址导航
  11. Mysql联表查询(学生表、教师表、成绩表、课程表)
  12. 台式计算机主板检测与维修,主板故障!教你如何用主板诊断卡检测维修电脑主板故障...
  13. 海银财富领军人物:韩宏伟(军人企业家)
  14. 【720开发】 spring boot 快速入门
  15. 在C或C++中如何使用PI(π)值
  16. Xilinx FPGA 引脚功能详细介绍
  17. [4G5G专题-104]:部署 - LTE网络性能指标KPI的全面描述与分析
  18. 参考文献中常见的会议论文的出版地址
  19. PE文件的简单加壳和脱壳(UPX和PEiD)
  20. 毕业论文查重是怎样查的?

热门文章

  1. Failed to declare queue(s):[XXX]问题解决
  2. cf Educational Codeforces Round 54 C. Meme Problem
  3. SSM项目跨域访问处理(含白名单处理)
  4. python运动目标绘制轨迹_实时轨迹绘制Matplotlib
  5. 图片工具picpick
  6. android+客户端+教程,Android新浪客户端开发教程完整版.pdf
  7. maven项目转gradle
  8. [含lw+源码等]javaweb银行柜员业务绩效考核系统
  9. Root后安装Xposed框架卡Logo问题
  10. iOS 普陀大学堂APP隐私政策