Python 3.x 使用python3.8的mysql数据库不会发生数据插入

Python 3.x 使用python3.8的mysql数据库不会发生数据插入,python-3.x,phpmyadmin,Python 3.x,Phpmyadmin,我无法将数据插入MySQL数据库。 获取以下消息。请建议 cursor.execute(““插入DHT11串行(湿度、温度)值(%s,%s)”,70.0,32.0) 它提供了以下内容: 仅供参考,我正在使用python 3.8.3 请查找整个脚本: 导入序列号 导入MySQLdb 导入时间 dbConn=MySQLdb.connect(“localhost”、“root”、“dbserial”)或die(“无法连接到数据库”) #打开指向数据库的游标 cursor=dbConn.cursor(

我无法将数据插入MySQL数据库。 获取以下消息。请建议

cursor.execute(““插入DHT11串行(湿度、温度)值(%s,%s)”,70.0,32.0)

它提供了以下内容:

仅供参考,我正在使用python 3.8.3

请查找整个脚本:

导入序列号

导入MySQLdb

导入时间

dbConn=MySQLdb.connect(“localhost”、“root”、“dbserial”)或die(“无法连接到数据库”)

#打开指向数据库的游标

cursor=dbConn.cursor()

设备='COM18'#必须将其更改为您正在使用的串行端口

尝试:

打印“正在尝试…”,设备

arduino=串行。串行(设备,9600)

除:

打印设备上的“连接失败”

尽管如此: 尝试:

最后: cursor.close()#在失败时关闭
您是否最终提交了更改?嗨,是的,我也尝试了提交。但是没有运气。问题是一旦我执行了它返回的insert语句:附加整个脚本请在描述中找到整个脚本。@SoumyaranjanMahapatra,找到解决方案了吗?我也面临同样的问题。你最终提交更改了吗?嗨,是的,我也尝试过提交。但是没有运气。问题是一旦我执行了它返回的insert语句:附加整个脚本请在描述中找到整个脚本。@SoumyaranjanMahapatra,找到解决方案了吗?我也面临同样的问题
  time.sleep(2)

  data = arduino.readline()  #read the data from the arduino

  print data

  pieces = data.split(" ")  #split the data by the tab

  #Here we are going to insert the data into the Database

  try:

    cursor.execute("INSERT INTO dht11serial (humidity,temperature) VALUES (%s,%s)", (pieces[0],pieces[1]))

    dbConn.commit() #commit the insert

    cursor.close()  #close the cursor
  except MySQLdb.IntegrityError:
    print "failed to insert data"
except:
  print "Failed to get data from Arduino!"