|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
import pymysql
conn = pymysql.connect(host='localhost',user='root',password='123456',db='app',charset='utf8')
报错:
Traceback (most recent call last):
File "D:\Python\Django\FFT\mysql.py", line 22, in <module>
conn = pymysql.connect(host='localhost',user='root',password='123456',db='app',charset='utf8')
File "D:\Python\Django\venv\lib\site-packages\pymysql\connections.py", line 355, in __init__
self.connect()
File "D:\Python\Django\venv\lib\site-packages\pymysql\connections.py", line 635, in connect
self._request_authentication()
File "D:\Python\Django\venv\lib\site-packages\pymysql\connections.py", line 842, in _request_authentication
self.user = self.user.encode(self.encoding)
TypeError: encode() argument 'encoding' must be str, not Charset
找个各种解决办法,已经使用的是UTF8了,网上多数都是用的UTF-8的。
后来尝试:
怀疑MYSQL的数据库格式和PYMYSQL对不起来,所以统一修改UTF-8
修改了connection.py中的default-charset为utf-8,
使用
conn = pymysql.connect(host='localhost',user='root',password='123456',db='app',charset='utf-8')
又报了一个新错误。
Traceback (most recent call last):
File "D:\Python\Django\FFT\mysql.py", line 22, in <module>
conn = pymysql.connect(host='localhost',port=3306,user='root',password='123456',database='app')
File "D:\Python\Django\venv\lib\site-packages\pymysql\connections.py", line 355, in __init__
self.connect()
File "D:\Python\Django\venv\lib\site-packages\pymysql\connections.py", line 635, in connect
self._request_authentication()
File "D:\Python\Django\venv\lib\site-packages\pymysql\connections.py", line 840, in _request_authentication
charset_id = charset_by_name(self.charset).id
AttributeError: 'NoneType' object has no attribute 'id'
Process finished with exit code 1
....求助大佬。。。。
|
|