python报错总结

版权声明:jiachuan的博客 https://blog.csdn.net/jiachuan/article/details/86626453

1.AttributeError: module ‘pymysql’ has no attribute ‘cursors’
代码

#!/usr/bin/python3

import pymysql



conn = pymysql.connect(host='218.245.0.109', port=3306, user='***', passwd=‘***', db='test')
cursor = conn.cursor()

cursor.execute("SELECT VERSION()")

# 使用 fetchone() 方法获取单条数据.
data = cursor.fetchone()

print("Database version : %s " % data)

# 关闭数据库连接

cursor.close()

报错:

AttributeError: module 'pymysql' has no attribute 'cursors'

纳尼,什么时候pymysql会没有cursors这个属性?上网搜,有人说本地有文件叫pymysql.py,我没有啊。
后来问大神,大神指点江山,你是不是文件名起成关键字了。我一看文件名,token.py改成aaa.py,运行,好了。。。

猜你喜欢

转载自blog.csdn.net/jiachuan/article/details/86626453