感谢@Alexis的编辑! =)
您好,这是我第一次打电话求助,我是python的新手,并尝试在mysql数据库中插入,但无法成功......任何想法? 提前谢谢了, →
这是代码:
insert_query = ("insert into mydb.Ticker_Value "
"(Ticker_name, Ticker_Value_date, Ticker_Value_high, Ticker_Value_low, Ticker_Value_open, Ticker_Value_close, Ticker_Value_volume) "
"VALUES (", Save_tckr, Save_date, float(Save_high[0]), float(Save_low[0]), float(Save_open[0]), float(Save_close[0]), float(Save_volume[0]), ")")
print (insert_query)
cursor_ins.execute(insert_query) #-- he aquí los problemas
这是结果:
/System/Library/Frameworks/Python.framework/Versions/2.7/bin/python2.7 /Users/luciano/PycharmProjects/finance_marketplace/extract.py
File "/Users/luciano/PycharmProjects/finance_marketplace/extract.py", line 74, in <module>
('insert into mydb.Ticker_Value (Ticker_name, Ticker_Value_date, Ticker_Value_high, Ticker_Value_low, Ticker_Value_open, Ticker_Value_close, Ticker_Value_volume) VALUES (', u'A', '2015-11-27', 42.2, 41.16, 41.32, 41.97, 1935738.0, ')')
cursor_ins.execute(insert_query) #-- this is what gives me the creeps! =)
File "/Library/Python/2.7/site-packages/mysql/connector/cursor.py", line 492, in execute
stmt = operation.encode(self._connection.python_charset)
AttributeError: 'tuple' object has no attribute 'encode'
Process finished with exit code 1