【发布时间】:2018-11-15 11:04:29
【问题描述】:
我在 python 脚本中使用 psycopg2 连接到 Redshift 数据库,偶尔收到如下错误:
psycopg2.OperationalError:SSL SYSCALL 错误:检测到 EOF
这个错误只发生过一次,在 90% 的时间里脚本都能正常工作。
我尝试将其放入 try 和 except 块中以捕获错误,但似乎捕获不起作用。例如,我尝试捕获错误,以便在发生这种情况时自动向我发送电子邮件。但是,发生错误时未发送电子邮件。以下是我的尝试代码,除了:
try:
conn2 = psycopg2.connect(host="localhost", port = '5439',
database="testing", user="admin", password="admin")
except psycopg2.Error as e:
print ("Unable to connect!")
print (e.pgerror)
print (e.diag.message_detail)
# Call check_row_count function to check today's number of rows and send
mail to notify issue
print("Trigger send mail now")
import status_mail
print (status_mail.redshift_failed(YtdDate))
sys.exit(1)
else:
print("RedShift Database Connected")
cur2 = conn2.cursor()
rowcount = cur2.rowcount
我在日志中收到的错误:
Traceback(最近一次调用最后一次): 文件“/home/ec2-user/dradis/dradisetl-daily.py”,第 579 行,在 load_from_redshift_to_s3() 文件“/home/ec2-user/dradis/dradisetl-daily.py”,第 106 行,在 load_from_redshift_to_s3 分隔符为“,”; """.format(YtdDate, s3location)) psycopg2.OperationalError:SSL SYSCALL 错误:检测到 EOF
所以问题是,是什么导致了这个错误,为什么我的尝试除了阻止它之外没有?
【问题讨论】:
标签: python amazon-redshift psycopg2