Flask Sql-Alchemy,sqlalchemy.exc.OperationalError:

我正在编写一个 flask 应用程序,它使用 flask-sqlalchemy 库与 AWS RDS 中的 postgres 服务器通信。

该应用程序仅使用用户名和密码即可正常工作。但是我创建了一个 IAM 用户并允许他使用令牌登录到 postgres(使用 boto3 的函数“generate_db_auth_token()”)。使用令牌登录得到以下错误。

'sqlalchemy.exc.OperationalError:(psycopg2.OperationalError)致命:用户“abc”的 PAM 身份验证失败'

这是我使用令牌的 SQLALCHEMY_DATABASE_URI,

"postgresql+psycopg2://"+get_conn()[0]['user']+":"+str(get_conn()[0]['password'])+"@"+get_conn()[0]['host']+":"+str(get_conn()[0]['port'])+"/common?sslmode=verify-ca&sslrootcert=/home/ec2-user/root.pem"

我在这里做错了什么吗?


宝慕林4294392
浏览 158回答 2
2回答

海绵宝宝撒

用这个:sqlalchemy.engine.url.URL.create(     drivername='postgresql+psycopg2',     username='postgres',     password='password',     host='localhost',     port=5432,     database='common')

温温酱

问题在于 URL 构造,如果您使用 AWS 令牌进行身份验证,请使用它来构造 URL。sqlalchemy.engine.url.URL('postgresql+psycopg2', username='postgres', password='password', host='localhost', port=5432, database='common')
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Python