Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/363.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/72.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 MySQL查询将创建的\u替换为更新的\u_Python_Mysql - Fatal编程技术网

Python MySQL查询将创建的\u替换为更新的\u

Python MySQL查询将创建的\u替换为更新的\u,python,mysql,Python,Mysql,我有以下Python MySQL查询: sql = "INSERT INTO Tweets(timestamp, message_id, body, username, symbol_id, created_at, updated_at) VALUES ('%s', '%s', '%s', '%s', '%s', '%s', '%s') ON DUPLICATE KEY UPDATE timestamp=VALUES(timestamp), message_id=VALUES(message_i

我有以下Python MySQL查询:

sql = "INSERT INTO Tweets(timestamp, message_id, body, username, symbol_id, created_at, updated_at) VALUES ('%s', '%s', '%s', '%s', '%s', '%s', '%s') ON DUPLICATE KEY UPDATE timestamp=VALUES(timestamp), message_id=VALUES(message_id), body=VALUES(body), username=VALUES(username), symbol_id=VALUES(symbol_id), created_at=NOW(), updated_at=NOW()"% \
(timestamp, messageId, body, username, dbID, currentTime, currentTime)
一切都很好,直到我点击DUPLOCATE KEY UPDATE上的
,其中
updated_at
被替换为
NOW()
时间戳。我试图删除
currentTime
updated\u at=NOW()
,但会出现以下错误:

Traceback (most recent call last):
  File "./parseTweets.py", line 50, in <module>
    (timestamp, messageId, body, username, dbID, currentTime)
TypeError: not enough arguments for format string
回溯(最近一次呼叫最后一次):
文件“/parseTweets.py”,第50行,在
(时间戳、messageId、正文、用户名、dbID、currentTime)
TypeError:格式字符串的参数不足

如果只是更新行,我不希望将
updated_at
替换为
created_at
,因此从
UPDATE
子句中删除
updated_at=NOW()
?另外,这很容易受到攻击。谢谢@univerio-我该如何修复SQL注入漏洞?在DBAPI
调用中使用参数。执行
调用,而不是
游标。执行(“插入tbl(foo)值('%s');%foo)
,执行
游标。执行(“插入tbl(foo)值(%s);”,(foo,)