python - str object is not callable when inserting into SQLite database -
i working on temperature sensor network using onewire temperature sensors runs on raspberry pi 2. following this tutorial , going along, realized setup 1 temperature sensor, whereas setup needs work multiple sensors.
as result of having multiple sensors, need able differentiate sensors 1 another. this, want have 3 columns in sqlite table. encountering error when execute python script supposed log readout sensor, date , time, , sensor name.
here problem, when configuring python script write 3 values table, error.
here code getting error when executing
#!/usr/bin/env python import sqlite3 import os import time import glob # global variables speriod=(15*60)-1 dbname='/var/www/templog.db' # store temperature in database def log_temperature(temp): conn=sqlite3.connect(dbname) curs=conn.cursor() sensor1 = 'sensor1' curs.execute("insert temps values(datetime('now'), (?,?))" (temp, sensor1)) # commit changes conn.commit() conn.close()
"insert temps values(datetime('now'), (?,?))" (temp, sensor1)
breaking down see creates string , parenthesis appears python function call. nonsensical because have string trying call function. hence error str
not being callable, bit cryptic if not experienced python. missing comma:
curs.execute("insert temps values(datetime('now'), (?,?))", (temp, sensor1))
now ?
placeholders correctly filled in.
often "str
not callable" error result of typos such or duplicated variable names (you think calling function variable contained string), start looking problems when see type of error.
Comments
Post a Comment