【问题标题】:psycopg2.InterfaceError: connection already closedpsycopg2.InterfaceError:连接已关闭
【发布时间】:2019-03-04 11:17:27
【问题描述】:

我正在使用 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

【问题讨论】:

  • 分享一些代码

标签: python django


【解决方案1】:

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

【讨论】:

    【解决方案2】:

    遗憾的是,它发生在 django 版本 1.3 和 1.4 中。请检查您的 postgres 日志以获取任何详细信息。 建议将 django 升级到最新版本。 请发布您的 django 和 postgres 版本。

    【讨论】:

    • Django==2.1.5, psycopg2==2.7.7 psycopg2-binary==2.7.7, psql (PostgreSQL) 版本为10.6
    猜你喜欢
    • 2013-12-11
    • 2012-03-14
    • 2021-05-04
    • 1970-01-01
    • 2015-10-08
    • 1970-01-01
    • 2018-04-11
    • 2020-12-03
    • 2018-09-23
    相关资源
    最近更新 更多