Python psycogp2 embeds help in postgresql

I have the following code to insert paste into my postgresql database

conn = psycopg2.connect("my connection setting are in here")
cur = conn.cursor()
cur.execute('INSERT INTO src_event (location_id, catname, title, name) VALUES (%i, \"%s\", \"%s\", \"%s\")' % (1441, "concert", item['title'], item['artists'] )) 

However, when I run this, I get the following error:

psycopg2.ProgrammingError: column "concert" does not exist
LINE 1: ...(location_id, catname, title, name) VALUES (1441, concert, "...

But the “concert” is not a column, it is a value, so I don’t understand why I get this error.

EDIT - I tried putting on a “round concert of value” and tried without

How can I get my data with this error?

+5
source share
1 answer

python - SQL injection. , " , " ( " / ..", ).

:

cur.execute('INSERT INTO src_event (location_id, catname, title, name) VALUES (%s, %s, %s, %s)', (1441, 'concert', item['title'], item['artists']))

, %s , .

. http://initd.org/psycopg/docs/usage.html#query-parameters.

+12

All Articles