Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.
for row in cursor.fetchall():
        currentid = str(row[0])


links = soup.findAll('a', {'class':'lightboxImage'})
for link in links:
        file_name = urllib2.unquote(url).decode('utf8').split('/')[-1]
        #print ("<img src=\"http:" + str(link['href'] + "\"</img>"))
        cursor.execute("INSERT INTO `Images`(`ImageURL`, `ProductID`) VALUES (" + "\"" + file_name + "\"" + " , " + currentid)

This is the error I'm getting when I run it.

root@eBayFileServer:~# python scrape.py
Traceback (most recent call last):
  File "scrape.py", line 102, in <module>
    cursor.execute("INSERT INTO `Images`(`ImageURL`, `ProductID`) VALUES (" + "\"" + file_name + "\"" + " , " + currentid)
  File "/usr/lib/python2.7/dist-packages/MySQLdb/cursors.py", line 174, in execute
    self.errorhandler(self, exc, value)
  File "/usr/lib/python2.7/dist-packages/MySQLdb/connections.py", line 36, in defaulterrorhandler
    raise errorclass, errorvalue
_mysql_exceptions.ProgrammingError: (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 '' at line 1")

I have tried all sorts of things, like changing the quotes around the data, but I just can't figure it out.

share|improve this question
1  
VALUES ( lacks a corresponding close paren ) at the end. –  Dan 41 mins ago
    
I added quotes around the paren to inc it, but get ^ SyntaxError: invalid syntax –  Andy 37 mins ago
    
You need a ) both in quotes and out of quotes. + ")"). The first one is for MySql, the second one is for Python. –  Dan 37 mins ago
    
Just spot that :P Thanks! –  Andy 36 mins ago

1 Answer 1

try this:

cursor.execute("INSERT INTO `Images`(`ImageURL`, `ProductID`) VALUES (" + "'" + file_name + "'" + " , " + currentid+");")

you can use single quotes so you don't need to escape double quotes and close the bracket from VALUES

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.