Python & Sqlalchemy - Connection pattern -> Disconnected from the remote server randomly

前端 未结 1 1195
甜味超标
甜味超标 2021-01-19 03:47

I\'m using a python for my backend API server. My backend connect to a DISTANT Postgres database using SQLALCHEMY (without flask-sqlalchemy because i need that connector eve

1条回答
  •  我在风中等你
    2021-01-19 04:11

    @skapin, I had solve the problem.As the server connect sql need a paramteter pool_pre_ping. how to fix “OperationalError: (psycopg2.OperationalError) server closed the connection unexpectedly”

    from flask_sqlalchemy import SQLAlchemy as _BaseSQLAlchemy
    
    class SQLAlchemy(_BaseSQLAlchemy):
        def apply_pool_defaults(self, app, options):
            super(SQLAlchemy, self).apply_pool_defaults(self, app, options)
            options["pool_pre_ping"] = True
    
    db = SQLAlchemy()
    

    0 讨论(0)
提交回复
热议问题