gpt4 book ai didi

python-3.x - Python Flask 应用程序无法连接到 redshift 数据库

转载 作者:行者123 更新时间:2023-11-29 12:51:29 29 4
gpt4 key购买 nike

我的简单 python flask 应用程序无法连接到 redshift 数据库。记录的错误:

psycopg2.OperationalError: could not create SSL context: library has no ciphers FATAL: no pg_hba.conf entry for host "::ffff:0.0.0.0", user "admin", database "redshiftdb", SSL off

但是当我尝试使用没有 flask 的简单 python(simple.py) 时,相同的连接效果很好。

import psycopg2

conn = psycopg2.connect(database="redshiftdb", user = "admin", password = "admin!pwd", host = "remotehost", port = "5439")

print ("Opened database successfully")

但是对于 flask 它不起作用(init.py)。

from flask import Flask
import psycopg2

@app.route("/service")
def service():
conn = psycopg2.connect(database="redshiftdb", user = "admin", password = "admin!pwd", host = "remotehost", port = "5439")
return "Service is running!"

if __name__ == "__main__":
app.run()
  • ubuntu v12
  • Python 版本:3.4
  • psycopg2==2.7.5
  • psycopg2-binary==2.7.5
  • flask ==1.0.2

最佳答案

尝试从源代码构建 psycopg2

pip install -r requirements.txt

包含在requirements.txt中

psycopg2==2.7.5 --no-binary :all:

关于python-3.x - Python Flask 应用程序无法连接到 redshift 数据库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52906544/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com