pymysql连结mysql数据库时报错:
AttributeError: 'NoneType' object has no attribute 'encode'
错误原因:
- pymysql.connect()中charset为’utf8’而不是’utf-8’
- 配置文件key值加了单引号
pymysql连结数据库:
import pymysql
try:
self.conn = pymysql.connect(host=host,port=port,user=username,passwd=passwd,db=database,charset=charasest)
except Exception as e:
print (e)
else:
print ('connect success {0}'.format(host))
self.cur = self.conn.cursor()