Error with INSERT QUERY from python script to insert data into MySQL database -


import mysqldb import datetime  water = {} water['time'] = 1500379234.16 water['resistance'] = 18.20 water['temperature'] = 21.9 water['time'] = datetime.datetime.fromtimestamp(water['time']).strftime('%y-%m-%d %h:%m:%s') #imports datetime   db = mysqldb.connect("localhost", "monitor", "password","wqms_database") curs = db.cursor()  curs.execute ("insert water_data values(water['time'], water['resistance'], water['temperature'])") 

error message:

mysql_exceptions.programmingerror: (1064, "you have error in  sql syntax; check manual corresponds mysql server version right syntax use near '['time'], water['resistance'], water['temperature']' @ line 1") 

the fields in database datetime, float , float respectively.

water['time'] not interpolated expected. parameterize variables this:

curs.execute ("insert water_data values(%s, %s, %s)", (water['time'], water['resistance'], water['temperature'])) 

Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -