Python使用pymysql执行insert语句报错、
content = ['17346204945874944', '信维通信', '300136', 'question', 107, '制造业', '2012-05-31 13:13:30', '2012-05-31 21:05:10', '苹果',
'answer',104, '信维通信', '2012-05-31 21:05:10', 7]
def save_to_cninfo(course_date):
sql_course = """INSERT INTO cninfo VALUES (%s,%s,%s,%s,%s,%s,str_to_date(if(%s='',null,%s),'%%Y-%%m-%%d %%H:%%i:%%s.%%f'),
str_to_date(if(%s='',null,%s),'%%Y-%%m-%%d %%H:%%i:%%s.%%f'),%s,%s,%s,%s,
str_to_date(if(%s='',null,%s),'%%Y-%%m-%%d %%H:%%i:%%s.%%f'),%s)"""
print(sql_course)
print(course_date)
cur.executemany(sql_course, course_date)
def save_mysql(content):
course_date = []
for item in content:
if not check_es_exist(item["indexId"]):
course_value = (
item["indexId"], item["companyShortName"], item["stockCode"], item["mainContent"], mainContentCount,
item["trade"][0],
date_format(item["pubDate"]), date_format(item["updateDate"]), item["authorName"],
item["attachedContent"],
attachedContentCount, item["attachedAuthor"], date_format(item["attachedPubDate"]), dateDiff)
course_date.append(course_value)
save_to_cninfo(course_date)
报错如下:
Traceback (most recent call last):
File "C:\Users\LiuDapao\AppData\Roaming\JetBrains\IntelliJIdea2021.1\plugins\python\helpers\pydev\pydevd.py", line 1483, in _exec
pydev_imports.execfile(file, globals, locals) # execute the script
File "C:\Users\LiuDapao\AppData\Roaming\JetBrains\IntelliJIdea2021.1\plugins\python\helpers\pydev\_pydev_imps\_pydev_execfile.py", line 18, in execfile
exec(compile(contents+"\n", file, 'exec'), glob, loc)
File "D:/Document/IDEA space/python/Crawlers/TestResponse.py", line 171, in <module>
main(index)
File "D:/Document/IDEA space/python/Crawlers/TestResponse.py", line 162, in main
save_mysql(content)
File "D:/Document/IDEA space/python/Crawlers/TestResponse.py", line 149, in save_mysql
save_to_cninfo(course_date)
File "D:/Document/IDEA space/python/Crawlers/TestResponse.py", line 113, in save_to_cninfo
cur.executemany(sql_course, course_date)
File "D:\App\application\anaconda3\lib\site-packages\pymysql\cursors.py", line 182, in executemany
self.rowcount = sum(self.execute(query, arg) for arg in args)
File "D:\App\application\anaconda3\lib\site-packages\pymysql\cursors.py", line 182, in <genexpr>
self.rowcount = sum(self.execute(query, arg) for arg in args)
File "D:\App\application\anaconda3\lib\site-packages\pymysql\cursors.py", line 146, in execute
query = self.mogrify(query, args)
File "D:\App\application\anaconda3\lib\site-packages\pymysql\cursors.py", line 125, in mogrify
query = query % self._escape_args(args, conn)
TypeError: not enough arguments for format string
debug去看了executemany的源码、发现在m = RE_INSERT_VALUES.match(query) 这一步的时候、m的值为none
目前不知道怎么解决、求指导、