我在尝试连接Cloud Run时不断收到错误,并且不断收到以下错误。知道吗?
__import__("pg8000") ModuleNotFoundError: No module named 'pg8000'
import pandas as pd
import sqlalchemy
import datetime
import requests
from urllib.parse import urlencode
import warnings
from flask import Flask
import os
import google
db_user = os.environ.get("DB_USER")
db_pass = os.environ.get("DB_PASS")
db_name = os.environ.get("DB_NAME")
cloud_sql_connection_name = os.environ.get("CLOUD_SQL_CONNECTION_NAME")
db = sqlalchemy.create_engine(
# Equivalent URL:
# postgres+pg8000://<db_user>:<db_pass>@/<db_name>?unix_sock=/cloudsql/<cloud_sql_instance_name>/.s.PGSQL.5432
sqlalchemy.engine.url.URL(
drivername='postgres+psycopg2',
username=db_user,
password=db_pass,
database=db_name,
query={
'unix_sock': '/cloudsql/{}/.s.PGSQL.5432'.format(
cloud_sql_connection_name)
}
),
# ... Specify additional properties here.
# ...
)
您需要安装一个受支持的数据库驱动程序。
如果要使用postgres+pg8000
,则需要安装pg8000
软件包,否则根据您的示例,实际上需要安装psycopg2
。