解决办法
import pymysql
user = input("user>>>").strip()
pwd = input("password>>>").strip()
# 建立连接
conn = pymysql.connect(host="127.0.0.1", port=3306, user=‘root‘, password=‘password‘, db=‘test‘, charset=‘utf8‘)
# 游标
cursor = conn.cursor()
# 执行sql语句
sql = "select * from userinfo where user=‘%s‘ and password = ‘%s‘" % (user, pwd)
# 受影响的行数
rows = cursor.execute(sql)
cursor.close()
conn.close()
if rows:
print("登录成功")
else:
print("登录失败")
将charset="utf-8" 改为utf8即可
python pymysql连接数据库 提示 'NoneType' object has no attribute 'encoding'