Python Forum

Full Version: Exception printed twice
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi,

I'm a little bit confused as the following code prints the exception provoked by the wrong password twice. Does anybody know why?

#!/usr/bin/python3

import pymssql, psycopg2
import psycopg2.extras
import sys

psqluser = "<USERNAME>"
psqlpassword = "<WRONG-PASSWORD>"
psqlserver = "<IP-ADRESSE>"
psqldatabase = "<DATABASE>"

try:
    psqlconn = psycopg2.connect(dbname=psqldatabase, user=psqluser, password=psqlpassword, host=psqlserver)
except Exception as err:
    print(err)
    exit(1)
Thanks
Richard
Can you post the exact complete error message?
I get only one Exception.

With your code, running on Python 3.12.5:
[deadeye@nexus ~]$ python test.py 
could not translate host name "<IP-ADRESSE>" to address: Name or service not known

[deadeye@nexus ~]$