diff --git a/PgDB.py b/PgDB.py index 6fcc570..5720d67 100644 --- a/PgDB.py +++ b/PgDB.py @@ -25,14 +25,23 @@ class PgDB(object): self.pwd = pwd self.db = db - def connect(self): - if self.con == 0: - try: - con = psycopg2.connect("dbname='%s' user='%s' host='%s' password='%s'" % (self.db,self.user,self.host,self.pwd)) - self.con = con - except Exception: - logging.fatal('An error occured during Postgresql database connection.', exc_info=1) - sys.exit(1) + def connect(self): + if self.con == 0: + try: + con = psycopg2.connect( + dbname=self.db, + user=self.user, + host=self.host, + password=self.pwd + ) + self.con = con + except Exception: + logging.fatal( + 'An error occured during Postgresql database connection (%s@%s, database=%s).', + self.user, self.host, self.db, exc_info=1 + ) + sys.exit(1) + return True def close(self): if self.con: