0

I'm trying to UPDATE some BLOB images in a database with the python-mysqldb package but i always get this error:

ValueError: unsupported format character ',' (0x2c) at index 64

I've successfully added the images some time ago with the execute substitution tools for example like this:

Set up connection to db:

db  = MySQLdb.connect( host="127.0.0.1", port=0815, user="javert", passwd="ureyes", db="some_db") 
cur = db.cursor()

read image files:

images = [ open( image_file, 'rb') for image_file in folder ]
image1, ..., image6 = images

insert images:

command = """INSERT INTO database_table (column1, ..., column6) VALUES (%s,%s,%s,%s,%s,%s)"""
cur.execute( command, args=( image1, ..., image6))
db.commit()

Now I've replaced the insert command with the following and get the described error:

"""UPDATE database_table SET column1=%s, column2=%s, column3=%s, column4=s%, column5=%s, column6=%s WHERE id=table_row_id"""

Thank You for your help!

3
  • Why don't you use pyodbc? Commented Dec 16, 2014 at 11:13
  • @SomethingSomething: I didn't know about this module. Could you describe the advantages of it compared to mysqldb? Why should i use it? Commented Dec 16, 2014 at 12:12
  • pyodbc is compatible with more libraries and does not need mysql dlls for its installation. I now noticed that mysql-python was updated more recently, so I don't know what's better Commented Dec 16, 2014 at 13:03

1 Answer 1

2

column4=s%, should be column4=%s, (note the inverted , and s).

Observe that this is what the error message says (, isn't an appropriate "format character"): the "format character" is what comes after the %, and , is not a valid one.

Sign up to request clarification or add additional context in comments.

3 Comments

Problem solved. Now everything runs like charm. Thank you very much for your help and also for the description of the error. I promise i will check that first next time! '
@ChristianKaiser Don't worry — I didn't mean to imply you should have known, you need to learn about that error one day before you can recognize it : )
I resent because i should have take a look into it but i ways so busy trying to find a mysqldb related format problem because i took my some trial and error to get the execute logic work with blobs. So thanks again for pointing it out and have a nice Christmas with your family.

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.