以下是代码
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,无论传递的是否是非空字符集参数。
这是MySQL版本问题吗?(版本8.0.1-dmr)
发布于 2017-12-04 04:07:17
要扩展上述只接受链接的答案,请考虑在当前的pymysql安装中进行以下更改。在MySQL 8中,mysql-python API不能识别可能较新的字符集,因此不能识别引发的KeyError。
要解决此问题,请在以下目录中的pymysql模块下找到connectors.py脚本:
print(pymysql.__file__)备份原始connectors.py脚本。然后合并以下更改。
原始(1268-1269行)
self.server_language = lang
self.server_charset = charset_by_id(lang).name 替换( 1268 -1272行)
self.server_language = lang
try:
self.server_charset = charset_by_id(lang).name
except KeyError:
self.server_charset = None注意在上面的行缩进中包含隐藏的制表符。
参考
发布于 2017-08-11 02:42:10
但是你的变量在哪里呢?
import pymysql
|
v
myVariable = pymysql.connect(
host='localhost',
port=3306,
user='root',
password='iDontWannaSay',
db='iDontWannaShow',
charset='utf8'
)https://stackoverflow.com/questions/45368336
复制相似问题