Traceback (most recent call last):
File "E:/Project/python/readMysql.py", line 20, in <module>
conut = cursor.execute(sql)
File "C:\Python35-32\lib\site-packages\pymysql\cursors.py", line 166, in execute
result = self._query(query)
File "C:\Python35-32\lib\site-packages\pymysql\cursors.py", line 323, in _query
self._do_get_result()
File "C:\Python35-32\lib\site-packages\pymysql\cursors.py", line 339, in _do_get_result
self._show_warnings()
File "C:\Python35-32\lib\site-packages\pymysql\cursors.py", line 347, in _show_warnings
ws = self._get_db().show_warnings()
File "C:\Python35-32\lib\site-packages\pymysql\connections.py", line 780, in show_warnings
result.read()
File "C:\Python35-32\lib\site-packages\pymysql\connections.py", line 1304, in read
first_packet = self.connection._read_packet()
File "C:\Python35-32\lib\site-packages\pymysql\connections.py", line 970, in _read_packet
(packet_number, self._next_seq_id))
pymysql.err.InternalError: Packet sequence number wrong - got 139 expected 1
请问如何解决?
这个问题已经确定是0.7.7的一个BUG了,作者已经修复了这个漏洞,发布了0.7.9的版本,升级为0.7.9就可以了。
这个问题应该是PyMySQL的一个BUG,你输入pip uninstall pymysql然后会问你是否卸载输入y。
然后输入pip install pymysql==0.7.6 回车就可以了
安装0.7.6的版本就可以了。
通过实验我发现是因为数据中urlname这一列存在空字符(是空字符,而不是NULL),这个问题我已经在github上与pymysql的团队取得了联系,看他们后面是如何回复的。
0.7.7以上都有这个问题,如果不想使用0.7.6可以把那urlname为空的删除掉,或者对urlname做一个检查,不能为空字符。
再用数据库管理软件,打开数据库对应的表,看一下里面的数据,截个图出来。
把代码都贴出来看看
代码:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import pymysql.cursors
# 获取链接
connection = pymysql.connect(
host='localhost',
user='root',
password='1234',
db='wikiurl',
charset='utf8mb4'
)
try:
# 获取回话指针
with connection.cursor() as cursor:
# 查询语句
sql = "select `urlname`, `urlhref` from `urls` where `id` is not null"
conut = cursor.execute(sql)
print(conut)
finally:
connection.close()
_________________________________________________________________________________________________________________
数据库对应的表: