python - Got an error while connecting to database -


i unable connected database in linux using psycopg2. have postgresql installed in linux , code is:

import psycopg2  def testegg():      conn = psycopg2.connect("dbname = mydatabase user = postgres port = 5432")      cur = conn.cursor()     cur.execute("create table egg ( num integer, data varchar);")     cur.execute("insert egg values ( 1, 'a');")     conn.commit()      cur.execute("select num egg;")     row = cur.fetchone()      print row      cur.close()     conn.close()  testegg()    

and got error:

psycopg2.operationalerror: fatal:  ident authentication failed user "postgres" 

this code runs in windows7 got above mentioned error in linux. there need more in linux? suggestion appreciated. thank you.

it's not problem due code, due permission of postgres user.

you should create new user access database , replace :

conn = psycopg2.connect("dbname = mydatabase user = postgres port = 5432") 

by (replace <your_user> real user name ...)

conn = psycopg2.connect("dbname = mydatabase user = <your_user> port = 5432") 

to create new user on postgres, can use 'createuser' binary. documentation available here.


Comments

Popular posts from this blog

c# - how to write client side events functions for the combobox items -

exception - Python, pyPdf OCR error: pyPdf.utils.PdfReadError: EOF marker not found -