2017-12-18 112 views

回答

2

您可能试图将插入日期时间为字符串。使用datetime对象和let the database driver handle the type conversion automatically参数化:

from datetime import datetime 

date_string = "Sun, 17 Dec 2017 14:26:07 GMT" 

dt = datetime.strptime(date_string, "%a, %d %b %Y %H:%M:%S %Z") 

cursor.execute('INSERT INTO some_table (somecol) VALUES (%s)', (dt,)) 
相关问题