Skip to content

Empty OperationalError when I tried to connect with wrong credentials #1442

@luisrojas17

Description

@luisrojas17

This is a bug tracker
If you have a question, such has "how do you do X with Python/PostgreSQL/psycopg2" please write to the mailing list or open a question instead.

Please complete the following information:

  • OS: Windows 8
  • Psycopg version: 2.9.3
  • Python version: 3.10.4
  • PostgreSQL version: PostgreSQL 14.2, compiled by Visual C++ build 1914, 64-bit
  • pip version: 22.0.4

Describe the bug
When I tried to connect to database with wrong credentials, I did not a descriptive message about the problem.
By the way, some time ago another user reported the same problem (Empty OperationalError on connect #417) but, until now there is not any solution (the issue was closed).

Please let us know:

1: what you did

  • I defined two variables that wraps the credentials to connect to PostgreSQL database
  • I defined a variable to receive the connection
   import psycopg2
   import os
   
   try:
       USER = os.environ['postgres']
       PASSWORD = os.environ['xyz1'] #Password is wrong
       conn = psycopg2.connect(host="localhost", port="5432", database="exampleDB", user=USER, password=PASSWORD)
       .....

   except psycopg2.OperationalError as err:
       print("Error: ", err)
       conn = None

   finally:
       if conn is not None:
           conn.close

2: what you expected to happen

  • A descriptive message showing what happend

3: what happened instead

  • I just got hardcode string 'Error:'

If possible, provide a script reproducing the issue.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions