插入错误 - mysql 连接器 python 2.7

Insert ERROR - mysql connector python 2.7

我正在尝试将一些情绪分析结果(google 云语言 API)插入到 mysql 数据库中。我正在使用 mysql connector.

import mysql.connector
from google.cloud import language

cnx = mysql.connector.connect(user='blahuser', password='Blahpw',
                          host='BlahIP',
                          database='FeedbackDB')

cursor = cnx.cursor(buffered=True)
CoreSQL = ("SELECT ResID, TextResp FROM Response")
cursor.execute(CoreSQL)
client = language.Client()

for row in cursor:
    document = client.document_from_text(row[1])
    sent_analysis = document.analyze_sentiment()
    sentiment = sent_analysis.sentiment
    annotations = document.annotate_text(include_sentiment=True, include_syntax=True, include_entities=True)
    print(row[0], sentiment.score, sentiment.magnitude)
    ResID_ =row[0]
    PhraseSent_ = sentiment.score
    PhraseMag_ = sentiment.magnitude
    SQLInsertCmd = ("INSERT INTO PhraseAnalysis (ResID, PhraseSent, PhraseMag),  VALUES (%s,%s,%s)");
    cursor.execute(SQLInsertCmd, (ResID_, PhraseSent_,PhraseMag_))

cnx.commit()
cursor.close()
cnx.close()

我得到的错误表明我的 INSERT 语句有问题:

python tm16.py (1, -0.4, 2.2) Traceback (most recent call last): File "tm16.py", line 27, in <module> cursor.execute(SQLInsertCmd, (ResID_, PhraseSent_,PhraseMag_)) File "/usr/lib/python2.7/dist-packages/mysql/connector/cursor.py", line 559, in execute self._handle_result(self._connection.cmd_query(stmt)) File "/usr/lib/python2.7/dist-packages/mysql/connector/connection.py", line 494, in cmd_query result = self._handle_result(self._send_cmd(ServerCmd.QUERY, query)) File "/usr/lib/python2.7/dist-packages/mysql/connector/connection.py", line 396, in _handle_result raise errors.get_exception(packet) mysql.connector.errors.ProgrammingError: 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ' VALUES (1,-0.4,2.2)' at line 1

网上有很多INSERT的例子,我一直没法解析。编码新手——毫无疑问是一些简单的东西。有人可以指出我哪里出错了吗?

麦克

字段列表末尾后有一个不必要的逗号。