在 AWS 上使用 psycopg2 连接到 PostgreSQL 时出现错误 SCRAM 身份验证需要 libpq 版本 10 或更高版本

问题描述 投票:0回答:2

我正在尝试使用 Python 中的 psycopg2 访问 AWS 上的 PostgreSQL。 连接调用失败并显示错误消息:

SCRAM authentication requires libpq version 10 or above

>>> c = psycopg2.connect(dbname="test", user="user", password="***", host="HOSTNAME")
Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "/var/app/venv/staging-LQM1lest/lib64/python3.8/site-packages/psycopg2/__init__.py", line 122, in connect
    conn = _connect(dsn, connection_factory=connection_factory, **kwasync)
psycopg2.OperationalError: SCRAM authentication requires libpq version 10 or above

使用

yum list installed
检查已安装的 libpq 版本,看起来好像安装了 10 以上的版本:

libpq.aarch64                    14.3-2.amzn2.0.2                    @amzn2extra-postgresql14

操作系统是Amazon Linux 2 Python 是 Python 3.8.16

任何帮助将不胜感激。 彼得

python postgresql amazon-elastic-beanstalk
2个回答
0
投票

使用

psycopg2-binary
套件(
psycopg2

pip install psycopg2-binary

然后照常在代码中导入:

import psycopg2

我对 AWS lambda

public.ecr.aws/lambda/python:3.9
的基本映像也有同样的问题,但这为我解决了这个问题。


0
投票

psycopg2-binary
没有解决我的问题。

我的用例

我在使用 AWS lambda 函数时遇到了这个问题:作为 python 模块在本地虚拟环境 (venv) 中运行代码工作正常。但在 AWS 上的 lambda 函数中运行它失败并出现错误。

我的解决方案

将架构从

arm64
更改为
x86_64
解决了问题

© www.soinside.com 2019 - 2024. All rights reserved.