When I run my code I get the following error.
2019-10-22 09:14:24 [scrapy.utils.signal] ERROR: Error caught on signal handler: BooksSpider.close of > Traceback (most recent call last): File "/home/mx/python-virtual-environments/scrapy/lib/python3.5/site->packages/MySQLdb/cursors.py", line 204, in execute query = query % args TypeError: not all arguments converted during bytes formatting
During handling of the above exception, another exception occurred:
Traceback (most recent call last): File "/home/mx/python-virtual-environments/scrapy/lib/python3.5/site->packages/twisted/internet/defer.py", line 151, in maybeDeferred result = f(*args, **kw) File "/home/mx/python-virtual-environments/scrapy/lib/python3.5/site->packages/pydispatch/robustapply.py", line 55, in robustApply return receiver(*arguments, **named) File "/home/mx/Desktop/books_crawler/books_crawler/spiders/books_SQL.py", line 79, in close cursor.execute("INSERT IGNORE INTO books_table(title, description, rating, upc, >availability)" "VALUES('%s', '%s', '%s', '%s')", row) File "/home/mx/python-virtual-environments/scrapy/lib/python3.5/site->packages/MySQLdb/cursors.py", line 206, in execute raise ProgrammingError(str(m)) MySQLdb._exceptions.ProgrammingError: not all arguments converted during bytes formatting
I tried reformatting the '%s' numerous ways but don't know what I am doing wrong.
This is a snippet of my code: >
csv_data = csv.reader(open(csv_file))
row_count = 0 for row in csv_data: if row_count != 0: cursor.execute("INSERT IGNORE INTO books_table(title, description, rating, upc, >availability) VALUES('%s', '%s', '%s', '%s')", row) row_count += 1 mydb.commit() cursor.close()