Я пытаюсь сохранить в MySQL сломанные элементы с помощью Scrapy, мой код работал как шарм с scrapy 0.24, хотя в 1.0.1 у меня есть ошибки mysql, которые я не могу понять, откуда они взялись.Scrapy Ошибка вставки Mysql
Часть моего трубопровода:
def process_item(self, item, spider):
if item['date'] != "":
try:
sql = ("INSERT INTO "+item['tablename']+" VALUES (%s, %s, %s, %s, %s, %s)")
self.cursor.execute(sql,
(
item['id'],
item['title'],
item['link'],
item['body'],
item['date'],
json.dumps(item['images'])
))
self.conn.commit()
except MySQLdb.Error, e:
print "************** Error ************"
print "Error %d: %s" % (e.args[0], e.args[1])
print "************** End ************"
return item
Примеры значений моих вставок:
id : 234264953566255283759266697433875136366452113806L
date : 'September 10, 2014'
images : {'checksum': '839ea50f9275a821975e0b70ca8838df',
'path': 'full/4b1fc7128e958c47b451936d6b5636b6ddfd2b14.jpg',
'url': 'http://content.domain.com/origin/Spaces/Production/Cms/POLL/n64wjrlnh0ayoe2gxo26-q.png'}
link : 'http://www.example.com/178400/xxxxxx-xxxx-xxxx-xxx-xx.aspx'
body : '<div class="articlecontent" itemprop="articleBody"> \r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n <p>lorem ipsums</p>\r\n<p style="text-align:center">'
title : 'German Leadership Vies With U.S. in Global Popularity'
И outpout ошибка:
************** Error ************
Error 1064: You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server version for the right syntax to use near
'), 'http://www.example.com/178400/xxxxxx-xxxx-xxxx-xxx-xx.aspx' at line 1
************** End ************
Печатая запроса в терминале, каким образом его будет выполнен:
INSERT INTO tablename VALUES (1245845410931227995499360226027473197403882391305,
("\'lorem Ipsum\'",),
'http://www.example.com/178400/xxxxxx-xxxx-xxxx-xxx-xx.aspx',
(),
(),
'[]')",
Я думаю, что добавлены дополнительные запятые ",", хотя я не знаю, почему и как это исправить. Любая помощь оценивается, если необходимо, я могу предоставить любую дополнительную информацию.
****** ****** РЕДАКТИРОВАТЬ
После того, как я изменил% s в значение от "% s" на "?" я получаю различные ошибки
TypeError: not all arguments converted during string formatting
on the line : json.dumps(item['images'])