Skip to content Skip to sidebar Skip to footer

Programmingerror: Not All Arguments Converted During String Formatting

I am trying to insert a data into a BLOB column in MySQL Server it is keep giving me this error: ProgrammingError: not all arguments converted during string formatting I could not

Solution 1:

According to the Python Database Specification in PEP 249, the format used in a query to show where to insert the parameters depends on the paramstyle member of the database module:

  • if it is qmark, use ? (question mark)
  • if it is numeric, use :1, :2 etc. (numeric, positional style)
  • if it is named, use :name (named style)
  • if it is format, use %s (ANSI C printf format codes)
  • if it is pyformat, use %(name)s (Python extended format codes)

AFAIR, MySQLdb uses format, so you should replace your ? with %s. (If MySQLdb would properly use prepared statements, it would be qmark and ? was the right way to go.)

Solution 2:

Sorted!!!! just found the solution,

1 - apparently i could not use ? because of the format specifier, 2 - and i also did not add the con for not only being able to retrive but also to insert in the database,

here is the example of the code that worked for me:

import MySQLdb

hostname = ''
username = ''
password = ''
database = ''

myConnection = MySQLdb.connect( host=hostname, user=username, passwd=password, db=database )


def doQuery() :

    fin  = open("hovik.jpg",'rb')
    contents = fin.read()
    fin.close()

    with myConnection:
        cur = myConnection.cursor()
        sql = "INSERT INTO image VALUES (%s)"

        ret = cur.execute(sql, [contents])

doQuery()
myConnection.close()

Post a Comment for "Programmingerror: Not All Arguments Converted During String Formatting"