我使用python查询PostgreSQL,有时当我运行代码时,我得到以下内容:
psycopg2.OperationalError: ERROR: pgbouncer cannot connect to server
我正在寻找有关如何处理异常的建议。
代码:
import psycopg2
while True:
conn = psycopg2.connect(database="****", user="**, password="****", host="bdl****", port="5400")
cur = conn.cursor()
print ("Opened database successfully")
try:
cur.execute('''select * from abc;''')
conn.commit()
conn.close()
except psycopg2.OperationalError:
continue
break