V2EX 15小时前
[Python] psycopg2 查询 sql 时报错
index_new5.html
../../../zaker_core/zaker_tpl_static/wap/tpl_guoji1.html

 

文章探讨了在Python中连接PostgreSQL数据库时出现的连接异常问题,分析了错误代码和可能原因,并提供了排查意见。

V 友们,帮忙给点排查意见

问题不是必现的,偶尔就出现一次

问了 AI 给的也是模糊的的回答

连接 pg 数据库用的是 pool = PooledDB()

执行代码如下

    def dbQuery(self, sql):        conn = pool.connection()        cur = conn.cursor()        cur.execute(sql)        result = cur.fetchall()        cur.close()        conn.close()        return result

报错如下:

could not receive data from server: Software caused connection abort (0x00002745/10053)Traceback (most recent call last):  File "aaTestV5.py", line 844, in process    input_values = self.getInputValuesInfo()  File "aa_process.py", line 117, in getInputValuesInfo    order_list = super(tf, self).getInputValuesInfo()  File "aaTestV5.py", line 555, in getInputValuesInfo    results_fromno, no_list = self.getFromnoResult()  File "aa_process.py", line 366, in getFromnoResult    return self.getFromnoResultInner(False)  File "aa_process.py", line 320, in getFromnoResultInner    results_fromno, no_list = super(tf, self).getFromnoResult(True)  File "aaTestV5.py", line 119, in getFromnoResult    result_fromno1 = self.dbQuery(query_sql)  File "aa_process.py", line 391, in dbQuery    return super(tf, self).dbQuery(sql)  File "aaTestV5.py", line 823, in dbQuery    cur.execute(sql)  File "\python\lib\site-packages\dbutils\steady_db.py", line 598, in tough_method    result = method(*args, **kwargs)  # try to executepsycopg2.DatabaseError: could not receive data from server: Software caused connection abort (0x00002745/10053)

Fish AI Reader

Fish AI Reader

AI辅助创作,多种专业模板,深度分析,高质量内容生成。从观点提取到深度思考,FishAI为您提供全方位的创作支持。新版本引入自定义参数,让您的创作更加个性化和精准。

FishAI

FishAI

鱼阅,AI 时代的下一个智能信息助手,助你摆脱信息焦虑

联系邮箱 441953276@qq.com

相关标签

数据库连接 Python PostgreSQL 异常排查 连接异常
相关文章