首页 > 数据库技术 > 详细

python pymysql连接数据库 提示 'NoneType' object has no attribute 'encoding'

时间:2021-05-17 00:29:28      阅读:26      评论:0      收藏:0      [点我收藏+]

解决办法

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'

原文:https://www.cnblogs.com/wxvirus/p/14774838.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!