Skip to main content
 首页 » 编程设计

python之psycopg2.InterfaceError : connection already closed

2024年11月24日8yyy_WW

我正在使用 psycopg2 访问 Django 项目中的 postgresql 数据库。执行一个大约需要 30 分钟的函数,然后将结果保存到数据库中时 出现如下异常

self.connection.autocommit = autocommit Internal Server Error: 
/dashboard/ajax/playbookRunner/39 Traceback (most recent call last):  
File "env/lib/python3.6/site-packages/django/db/backends/postgresql/base.py", line 238, in _set_autocommit 
self.connection.autocommit = autocommit psycopg2.InterfaceError: connection already closed 

有什么想法吗?

Django==2.1.5,psycopg2==2.7.7 psycopg2-binary==2.7.7,psql(PostgreSQL)版本为10.6

请您参考如下方法:

使用 WSGI 部署解决了问题这里是文档的链接 https://docs.djangoproject.com/en/2.2/howto/deployment/wsgi/