我对python pgsql库有一个奇怪的“问题”。 在我的代码中,我处理错误并打印它,发生它打印2次。
这是代码:
def pg_connect():
con = None
try:
con = psycopg2.connect(database=odoo_array['DBName'], user=odoo_array['User'], password=odoo_array['Password'], host=odoo_array['Host'], port=odoo_array['Port'])
cur = con.cursor()
except psycopg2.DatabaseError, e:
print "["+cur_date()+"] Error: "+str(e)
sys.exit(1)
finally:
if con:
return cur
def cur_date():
date = datetime.datetime.now().strftime( "%Y-%m-%d %H:%M:%S" );
return date
当连接出错时,我想要输出,我得到了这个:
[2015-08-12 09:09:46] Error: could not connect to server: Connection refused
Is the server running on host "localhost" and accepting
TCP/IP connections on port 65432?
could not connect to server: Connection refused
Is the server running on host "localhost" and accepting
TCP/IP connections on port 65432?
无法理解为什么我会错误2次?