Skip to content Skip to sidebar Skip to footer

Python: Unsupported Format Character ''' (0x27) At Index 350

I've got this error using the MySQL db backend for django. The query I'm trying to execute (it worked perfectly with MariaDB connector): cursor.execute('SELECT a.*, COALESCE( NULLI

Solution 1:

Django does not use ? for the parameterization, rather it uses format string style parameters, i.e. '%s' % 'hello', etc. See Passing parameters into raw [Django docs].

It looks like you want to make a query of the form LIKE '<SOMETHING>%', firstly do not use ? (use %s instead), next instead of trying to concatenate in the query concatenate in python itself.

Hence you query should be like (Truncated irrelevant parts):

cursor.execute("SELECT ... a.gene_name LIKE %s ORDER BY ...", ('{}%'.format(gene),))

Post a Comment for "Python: Unsupported Format Character ''' (0x27) At Index 350"