Failure instance: Traceback: : (1241, ‘Operand should contain 1 column(s)’)

在使用scrapy框架过程中,pipelines.py文件中的(写入mysql的)pipe类执行的时候报错:Failure instance: Traceback: <class 'MySQLdb._exceptions.OperationalError'>: (1241, 'Operand should contain 1 column(s)')
原因是:传递的参数,与实际的类型不符(比如下面的item['content']其实是list类型,而我当%s传入了),还有传递的item['keyname']必须存在,否则执行报key error

def do_insert(self, cursor, item):
insert_sql = """insert into scrapy_result (name,url,url_data,title,body,content)
values (%s,%s,%s,%s,%s,%s)"""
print(type(item['content']))
params = (item['name'], item['url'], item['url_data'],item['title'], item['body'], item['content'])
cursor.execute(insert_sql, params)

You may also like...

发表评论