我目前正在尝试使用python将数据发送到我在Web上托管的数据库。没有抛出MySql错误但是在忍者中运行我得到了这个输出:
Traceback (most recent call last):
File "/home/nekasus/tryme.py", line 8, in <module>
port = "3306") # name of the data base
File "/usr/lib/python2.7/dist-packages/MySQLdb/__init__.py", line 81, in Connect
return Connection(*args, **kwargs)
File "/usr/lib/python2.7/dist-packages/MySQLdb/connections.py", line 187, in __init__
super(Connection, self).__init__(*args, **kwargs2)
TypeError: an integer is required
这是我的代码:
import fakevalues
import MySQLdb
fakevalues.randomnumber()
db = MySQLdb.connect(host="sql8.freemysqlhosting.net",
user="sql8167767",
passwd="placeholder",
db="sql8167767",
port = "3306")
cur = db.cursor()
try:
cur.execute("INSERT INTO hydroponics (ph, electricalconductivity, nutrientsolutiontemperature, nutrientsolutiondepth) VALUES (1, 1, 1, 1)")
except MySQLdb.Error as e:
print(e)
db.close()
答案 0 :(得分:1)
您错过了提交。
db.commit()
答案 1 :(得分:0)
port
需要是整数,而不是字符串。