Click here to Skip to main content
15,886,587 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
import sys
import os
import time
import calendar
#import MariaDB
#import phpMyAdmin
import MySQLdb
#import pymysql
import time
from time import *

lt = localtime()


file = open('/sys/bus/w1/devices/28-030797798738/w1_slave')
filecontent = file.read()
file.close()
stringvalue = filecontent.split("\n")[1].split(" ")[9]
temperatur_sensor1 = float(stringvalue[2:]) / 1000
print "hhhhhhh", temperatur_sensor1
connection = MySQLdb.connect (host="localhost", user="Smart", passwd="123456", db="mysql", charset='utf8')

cursor = connection.cursor()
cursor.execute("""CREATE TABLE IF NOT EXISTS temperatur6 (temperatur6 FLOAT(5))""")
print "ggggggg", temperatur_sensor1
cursor.execute("INSERT INTO temperatur6 VALUES ( '%s' ) "),(temperatur_sensor1)
print "ffffff", temperatur_sensor1

connection.commit()
cursor.close();

sys.exit(0)


The Waring is?___________________________________________________________


Test_1.py:37: Warning: Incorrect double value: '%s' for column 'temperatur6' at row 1
  cursor.execute("INSERT INTO temperatur6 VALUES ( '%s' ) "),(temperatur_sensor1)


What I have tried:

I tried almost everythin already. Inset a %d or to delete the '' signs.
Posted
Updated 10-Jun-19 0:04am
v3
Comments
[no name] 9-Jun-19 10:13am    
Obsolete after Q EditYour table has one column 'temperatur6', but you try to insert two columns...

temperatur_sensor1 is a float value, not a string.
 
Share this answer
 
Comments
Member 14488635 9-Jun-19 11:12am    
Da soll aber eine Dezimalzahl wie z.Bsp: 29.44 rein. Was muss ich denn ändern? Danke!!
[no name] 9-Jun-19 12:03pm    
Du solltest in Englisch antworten ;)
Richard MacCutchan 10-Jun-19 3:37am    
This is an English language site. If you do not speak reasonable English you can use Google Translate.
Member 14488635 10-Jun-19 5:28am    
Sorry. I forgot to write in English.
I just want to know what I have to change in the code program? I am really glueless. Can you give me a hint? Please!
Richard MacCutchan 10-Jun-19 5:36am    
This is a guess as I do not have MySqldb on my system. But looking at the syntax of MySQL statements in the documentation I wonder if your quote characters and parentheses are correct. Try changing the INSERT to:
Python
cursor.execute("""INSERT INTO temperatur6 VALUES (%s) """,(temperatur_sensor1))
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900