【发布时间】:2021-04-24 19:15:56
【问题描述】:
我正在尝试使用 Python 代码从 GCP Cloud functions 连接到 PostgreSQL 的 CloudSQL 实例。我是 python 的新手,所以遇到了一些错误,需要帮助来修复错误
我的代码如下:
# Don't add the "/.s.PGSQL.5432 suffix" because it will already be added back automatically by the library...
import psycopg2
import sqlalchemy
from sqlalchemy import create_engine
engine = sqlalchemy.create_engine('postgresql+psycopg2://postgres:a1b2c3d4e190@X.X.X.X/postgres_dbase')
print("connected")
该功能已正常部署,但 URL 失败并出现以下错误
Error: could not handle the request
它在日志中显示以下错误
Details:'Request' object has no attribute '_instantiate_plugins'
直接执行代码就可以了
$ python3 open.py
connected
我正在使用Python 3.7
更新
看起来我必须设置 DATABASE_URL 但不确定如何在 CLoud 函数中设置它。在Cloud functions 的Runtime environmental variable 下方添加但没有运气
DATABASE_URL="sqlite://"
【问题讨论】:
标签: python-3.x postgresql google-cloud-functions psycopg2 google-cloud-sql