I am trying to use Python code to connect from GCP Cloud functions to PostgreSQL instance of CloudSQL . I am new to python , so struggling with some error and need help to fix the error
My code is as follows:
# 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:[email protected]/postgres_dbase')
print("connected")
The function is deployed fine but the URL is failing with below error
Error: could not handle the request
It is showing below error in the log
Details:'Request' object has no attribute '_instantiate_plugins'
It works fine when I execute the code directly
$ python3 open.py
connected
I am using Python 3.7
UPDATE
It looks like I have to set DATABASE_URL but not sure how to set it in CLoud functions . Added below Runtime environmental variable in Cloud functions but no luck
DATABASE_URL="sqlite://"