为了账号安全,请及时绑定邮箱和手机立即绑定

Flask Sql-Alchemy,sqlalchemy.exc.OperationalError:

Flask Sql-Alchemy,sqlalchemy.exc.OperationalError:

宝慕林4294392 2023-05-09 10:11:01
我正在编写一个 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"我在这里做错了什么吗?
查看完整描述

2 回答

?
海绵宝宝撒

TA贡献1809条经验 获得超8个赞

用这个:

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


查看完整回答
反对 回复 2023-05-09
?
温温酱

TA贡献1752条经验 获得超4个赞

问题在于 URL 构造,如果您使用 AWS 令牌进行身份验证,请使用它来构造 URL。

sqlalchemy.engine.url.URL('postgresql+psycopg2', username='postgres', password='password', host='localhost', port=5432, database='common')



查看完整回答
反对 回复 2023-05-09
  • 2 回答
  • 0 关注
  • 146 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信