I`m currently working on a scraper in python which collects emergency services announcements from a RSS feed. At the point where I want to add a announcement to my MySQL database I got a strange error. I can't find anything about it. It is about this part:
sql = "INSERT INTO meldingen(melding_title, melding_description, melding_category, melding_region, melding_location, melding_zipcode, melding_emergency, melding_date) VALUES ('%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s')"
uniqueRows.append(hash)
#print uniqueRows
# Execute the SQL command
cursor.execute(sql,(str(title), str(description), str(category), str(region), str(location), str(zipcode), str(emergency), date.strftime('%Y-%m-%d %H:%M:%S')))
# Commit your changes in the database
conn.commit()
I got the following error:
Traceback (most recent call last): File "C:/Users/Nicky/Documents/alarmeringen/P2000Scraper.py", line 83, in cursor.execute(sql,(str(title), str(description), str(category), str(region), str(location), str(zipcode), str(emergency), date.strftime('%Y-%m-%d %H:%M:%S'))) File "C:\\Python27\\lib\\site-packages\\MySQLdb\\cursors.py", line 220, in execute self.errorhandler(self, exc, value) File "C:\\Python27\\lib\\site-packages\\MySQLdb\\connections.py", line 36, in defaulterrorhandler raise errorvalue _mysql_exceptions.ProgrammingError: (1064, "Erreur de syntaxe pr\\xe8s de 'p 2 stank soort lucht: koolmonoxide/co vk: 6 troelstrakade dhg 7630'', ''Brandwe' \\xe0 la ligne 1")
I don't understand this whole error. If someone could help it would be great. Thanks.
You have a syntax error in your SQL
query. It even says so in the error you provided.
"INSERT INTO meldingen(melding_title, ....)
should be "INSERT INTO meldingen (melding_title, .....)
(note the space between the table's name and the parenthesis).
Don't quote placeholders when using the Python driver. It'll add the quotes for you. '%s'
should be %s
in each case.
See the documentation for more details.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.