Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/70.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 属性错误:';元组';对象没有属性';编码';_Python_Mysql_Python 2.7 - Fatal编程技术网

Python 属性错误:';元组';对象没有属性';编码';

Python 属性错误:';元组';对象没有属性';编码';,python,mysql,python-2.7,Python,Mysql,Python 2.7,感谢@Alexis的编辑!=) 你好,这是我第一次打电话寻求帮助,我是python新手,正在尝试在mysql数据库中进行插入,但无法成功。。。有什么想法吗? 多谢各位, L 代码如下: insert_query = ("insert into mydb.Ticker_Value " "(Ticker_name, Ticker_Value_date, Ticker_Value_high, Ticker_Value_low, Ticker_Value_open, Ticker_Value_clo

感谢@Alexis的编辑!=)

你好,这是我第一次打电话寻求帮助,我是python新手,正在尝试在mysql数据库中进行插入,但无法成功。。。有什么想法吗? 多谢各位, L


代码如下:

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
/System/Library/Frameworks/Python.framework/Versions/2.7/bin/python2.7/Users/luciano/PycharmProjects/finance\u marketplace/extract.py
文件“/Users/luciano/PycharmProjects/finance_marketplace/extract.py”,第74行,在
(“插入mydb.Ticker\u值(Ticker\u名称、Ticker\u值日期、Ticker\u值高、Ticker\u值低、Ticker\u值开放、Ticker\u值关闭、Ticker\u值量)值('、u'A'、'2015-11-27',42.2、41.16、41.32、41.97、1935738.0'))
cursor_ins.execute(insert_query)#——这让我毛骨悚然
文件“/Library/Python/2.7/site packages/mysql/connector/cursor.py”,第492行,在execute中
stmt=operation.encode(self.\u connection.python\u字符集)
AttributeError:“tuple”对象没有属性“encode”
进程已完成,退出代码为1

insert\u查询
是一个元组。您必须使用
+
insert\u将元素连接成一个字符串。查询是一个元组。您必须使用
+