1

I have a trouble with my program in my raspberry pi. This is my source code

import MySQLdb
import csv
db=MySQLdb.connect(user='root',passwd='toor',
                        host='127.0.0.1',db='data')
cursor=db.cursor()
csv_data=csv.reader(file('datasensor.txt'))
for row in csv_data:
        sql = "insert into `kelembapan` (`id`,`Tanggal`,`Tipe_sensor`,`Value`,`Ket`) values(%s,%s,%s,%s,%s);"
        cursor.execute(sql,row)
db.commit()
cursor.close()
print "The Data has been inputted"

and this is for txt file

1, 2017-10-10, sensor1,40,Kurang lembap
2, 2017-10-10, sensor2,60,Lembap

That program can run in my ubuntu but not in my raspberry. when run in raspberry there is error

Traceback (most recent call last):
 File "server.py", line 9, in <module>
  cursor.execute(sql,row)
 File "/usr/lib/python2.7/dist-packages/MySQLdb/cursors.py",line 159, in execute
  query = query% db.literal(args)
TypeError: not enough arguments for format strings

Thnks before :)

16
  • What happens when you try that same line of code using .format? check this out as it appears that way of doing it is being deprecated. Commented Jun 19, 2017 at 15:03
  • Check your CSV file for non-matching rows (i.e. less than 5 elements) Commented Jun 19, 2017 at 15:04
  • @Jimmy Smith when im using .format, there is error NameError: name 'Tanggal' is not defined Commented Jun 19, 2017 at 15:25
  • 1
    @zwer umm i have no idea. in my raspberry, my program isnt work. I'm using the same csv file in my ubuntu and raspberry Commented Jun 19, 2017 at 15:30
  • 1
    @cricket_007 thanks cricket. now I use sqlalchemy with pandas and work in my raspi. thank you very much bro :) Commented Jul 23, 2017 at 8:21

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.