I'm using Psycopg2 but I get an error message could it be because I'm using Window10?

0

My code is as follows:

import psycopg2
import pprint
import sys

def main():
    #Variable conexion
    cadenaConexion="host=localhost dbname=test1 user=postgres 
    password=admin"

    print("Cadena conexion a la BD\n ->%s"%(cadenaConexion))
    obj=psycopg2.connect(cadenaConexion)
    objCursor=obj.cursor()
    objCursor.execute("INSERT INTO tbltext(num, data) VALUES(%s,%s)",
    (26,"Enrique Cortez"))
    obj.commit()
    objCursor.execute("SELECT * FROM tblTest")
    registros=objCursor.fetchall()
    pprint.pprint(registros)
    #objCursor.close()
    #obj.close()

main()

If I execute the previous code I get the following result:

===== RESTART: C:\Users\Angel\Documents\Django pruebas\postgreSQL_.py 
=====
Cadena conexion a la BD
->host=localhost dbname=test1 user=postgres password=admin

Traceback (most recent call last):

File "C:\Users\Angel\Documents\Django pruebas\postgreSQL_.py", line 20, in 
<module>
main()

File "C:\Users\Angel\Documents\Django pruebas\postgreSQL_.py", line 10, in 
main
obj=psycopg2.connect(cadenaConexion)

File "C:\Python27\lib\site-packages\psycopg2\__init__.py", line 164, in 
connect
conn = _connect(dsn, connection_factory=connection_factory, async=async)

OperationalError: FATAL:  la autentificación password falló para el 
usuario «postgres»

What could be my problem?

    
asked by Angel Vargas 13.04.2017 в 16:16
source

1 answer

3

If you look at the last message it says:

FATAL:  la autentificación password falló para el 
usuario postgres

Basically that means that it does detect the user but that the password you entered is incorrect. It may be the case that you have entered the wrong password when you have created the user. Try resetting the password, making sure you are in the database test1 .

To do this, connect to it with psql -U postgres -d test1 and once you have connected, enter:

ALTER USER postgres WITH PASSWORD 'admin';

Greetings:)

    
answered by 23.04.2017 / 15:11
source