1

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()

1 Answer 1

0

checking mysql website, parameters are not enclosed in single quotes. might want to try this. I also removed the greater > symbol on your availability column.

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()
Sign up to request clarification or add additional context in comments.

1 Comment

Hello Metal, the greater symbol was accidentally added when I tried to add the code block here on Stackoverflow. I ran your query statement, but I still get the same error message. 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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.