这是密码
import pymysql
pymysql.connect(
host='localhost',
port=3306,
user='root',
password='iDontWannaSay',
db='iDontWannaShow',
charset='utf8'
)
错误回溯是:
data is :::::b'\xff\x02\x00\xff\x81\x15'....##### I was add near line 1279 which is print("data is :::::%s...."%data[i:i+6])
Traceback (most recent call last):
File "C:\Users\123\Desktop\pymysqldebug.py", line 8, in <module>
charset='utf8'
File "D:\Program Files (x86)\Python\Python35\lib\site-packages\pymysql\__init__.py", line 90, in Connect
return Connection(*args,**kwargs)
File "D:\Program Files (x86)\Python\Python35\lib\site-packages\pymysql\connections.py", line 709, in __init__
self.connect()
File "D:\Program Files (x86)\Python\Python35\lib\site-packages\pymysql\connections.py", line 934, in connect
self._get_server_information()
File "D:\Program Files (x86)\Python\Python35\lib\site-packages\pymysql\connections.py", line 1279, in _get_server_information
self.server_charset = charset_by_id(lang).name
File "D:\Program Files (x86)\Python\Python35\lib\site-packages\pymysql\charset.py", line 39, in by_id
return self._by_id[id]
KeyError: 255
似乎struct.unpack方法将“\xff\”解析为255并分配给 self.server_language
,无论传递的非null字符集参数是什么。
这是mysql版本问题吗 8.0.1-dmr
)
3条答案
按热度按时间kxxlusnw1#
若要扩展上述仅接受答案的链接,请考虑对当前链接进行以下更改
pymysql
安装。对于mysql 8,mysql python api无法识别可能较新的字符集,因此KeyError
.要解决此问题,请在
pymysql
在此目录中找到模块:备份original connectors.py脚本。然后合并以下更改。
原件(第1268-1269行)
更换(第1268-1272行)
注意在上面的行的缩进中包含隐藏的制表符。
参考
pymysql git补丁#591
y0u0uwnf2#
但是你的变量呢?
daolsyd03#
这个问题可以参考pull请求591