Python psycopg2 not inserting into postgresql table

If don’t want to have to commit each entry to the database, you can add the following line:

conn.autocommit = True

So your resulting code would be:

import psycopg2

try:
    conn = psycopg2.connect("dbname="djangostack" user="bitnami" host="localhost" password='password'")
    conn.autocommit = True
except:
    print "Cannot connect to db"

cur = conn.cursor()

try:
    cur.execute("""insert into cnet values ('r', 's', 'e', 'c', 'w', 's', 'i', 'd', 't')""")
except:
    print "Cannot insert"

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)