Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

just trying to take a picture with raspberry pi and inserting actual datetime and picture into mysql db... I've tried to insert just the datetime... thats fine. but I get an error inserting the image...

          image = open(picPath+filename, 'r')
            pic = image.read()
            mysql = MySQLdb.connect(host="local", user="root", passwd="bla", db="sexyimages")
            cur = mysql.cursor()
            sql = ("insert into test(SampleTime, picture) values(%s, %s)")
            cur.execute(sql, (jetzt, pic))
            mysql.commit()

Warning: Incorrect integer value: '????c?Exif' for column 'picture' at row 1 cur.execute(sql, (jetzt, pic))

anyone an idea?

oh ya using python-mysqldb

cheeers

share|improve this question
1  
no its declared as mediumblob.... –  jonny Nov 14 '14 at 19:59
    
ah, you might try changing the file opening mode from 'r' to 'rb' –  bernie Nov 14 '14 at 20:03
    
with 'rb' raspistill -v -o/home/pi/webcam/webcam-2014-11-14_20:05:53.jpg script.sh:51: Warning: Incorrect integer value: '????c?Exif' for column 'picture' at row 1 cur.execute(sql, (jetzt, pic)) with 'r' the same –  jonny Nov 14 '14 at 20:06

1 Answer 1

According to this answer I found that you have to close the file pointer first and escape the string using the MySQL.escape_string method. Try this:

image = open(picPath+filename)
pic = image.read()
image.close()

mysql = MySQLdb.connect(host="local", user="root", passwd="bla", db="sexyimages")
cur = mysql.cursor()
cur.execute("insert into test SET SampleTime='%s', picture='%s'") %(jetzt, MySQLdb.escape_string(pic))

mysql.commit()
share|improve this answer
    
raspistill -v -o/home/pi/webcam/webcam-2014-11-14_20:59:08.jpg script.sh:52: Warning: Incorrect integer value: '????d\0Exif\0\0MM\0*\0\0\\0\n\0\0\0\0\0\0\0\0\0\0\0\0\0\0?\0\0\0\0 \0\0\0?\0\0\0\0\n\0\0\0?\Z\0\0\0\' for column 'picture' at row 1 cur.execute(sql, (jetzt, MySQLdb.escape_string(pic))) :( still not the right cmd –  jonny Nov 14 '14 at 21:00
    
Edited answer. Added quotation marks around the values to insert. –  kiran.koduru Nov 14 '14 at 21:07
    
YES!!! no more errors...BUT no picture in the db... just 0. –  jonny Nov 14 '14 at 21:23
    
What do you get when you print pic –  kiran.koduru Nov 14 '14 at 21:24
    
a lot of undefined wild text. (?? ?S?????@Xm@?ʢ??????4$o-w63???V]?Il?RnQ?q??9??f%?????n?? ??$??8?9;???.@2?L???p ??U[p a??^???G???Z?چ???I__????{?Ryc? ̓U#{.?yS?1??d88??T?v?,?~??h???<?!?=??n J`?y???J?{UD????H?!N?ۂ???)D??՛????ke7i;4??Kw?????Ml_????'r0???Y?e!?$/Ur?WG?z??m?‌​B?ѐ$7F%?J??Tn?? ~\ ?%??S????@?*??P??\j8?*8f? –  jonny Nov 14 '14 at 21:35

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.