我试图创建一个函数来处理API错误消息,但是我在Python中得到了这个错误消息:
Exception has occurred: sqlite3.OperationalError
near "Test4": syntax error
服务器响应为:
^{2}$我的代码是:
def error():
if "message" in r.json():
logText = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime()) + " : " + r.json()['message']
c.execute("INSERT INTO log VALUES ('"+ logText +"')")
conn.commit()
if "validationErrors" in r.json():
logText = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime()) + " : " + r.json()['validationErrors'][0]
c.execute("INSERT INTO log VALUES ('"+ logText +"')")
conn.commit()
os._exit(1)
我不知道是什么导致了这个错误。任何帮助都将不胜感激。非常感谢。在
您发送的是这个SQL
INSERT INTO log VALUES ('2018-12-10 23:31:26 : Budget name must be unique. 'Test4 - X4574747-PHONE' already exits')
,正如您看到的,您在Test4
之前关闭了'
引号,这就是为什么SQL不理解结束引号之后发生了什么。在使用
?
表示从给定参数列表传递参数。它是[logText]
。最好使用这种方法来避免SQL注入。在见here
相关问题 更多 >
编程相关推荐