gpt4 book ai didi

python - 使用 psycopg2 的 aws localstack redshift 连接问题

转载 作者:太空宇宙 更新时间:2023-11-04 04:58:20 24 4
gpt4 key购买 nike

使用 localstack 模拟 AWS 服务。正在尝试使用 psycopg2 连接到本地 redshift 实例。但是连接超时。使用 boto3 的连接已成功完成。

client = boto3.client('redshift', endpoint_url='http://127.0.0.1:5439/')
print client.describe_clusters()
con = psycopg2.connect(dbname='test123', host='127.0.0.1', port=5439, user='user', password='password', connect_timeout=10)

输出:

{u'Clusters': [{u'NumberOfNodes': 1, u'AvailabilityZone': 'localhost', u'NodeType': 'ds1.large', u'PubliclyAccessible': True, u'MasterUsername': 'user', u'ClusterParameterGroups': [{u'ParameterGroupName': 'default.redshift-1.0', u'ParameterApplyStatus': 'in-sync'}], u'Encrypted': True, u'ClusterSecurityGroups': [{u'Status': 'active', u'ClusterSecurityGroupName': 'Default'}], u'AllowVersionUpgrade': False, u'VpcSecurityGroups': [], u'ClusterSubnetGroupName': 'testgroup', u'AutomatedSnapshotRetentionPeriod': 1, u'ClusterStatus': 'creating', u'ClusterIdentifier': 'test123', u'DBName': 'test123', u'PreferredMaintenanceWindow': 'Mon:03:00-Mon:03:30', u'ClusterVersion': '1.0'}], 'ResponseMetadata': {'RetryAttempts': 0, 'HTTPStatusCode': 200, 'RequestId': '384ac68d-3775-11df-8963-01868b7c937a', 'HTTPHeaders': {'date': 'Thu, 28 Sep 2017 05:54:46 GMT', 'content-length': '1264', 'content-type': 'text/html; charset=utf-8', 'server': 'amazon.com'}}}
Traceback (most recent call last):
File "/home/shrishinde/PycharmProjects/Test/redshift_test.py", line 46, in <module>
con = psycopg2.connect(dbname='test123', host='127.0.0.1', port=5439, user='user', password='password', connect_timeout=10)
File "/usr/local/lib/python2.7/dist-packages/psycopg2/__init__.py", line 130, in connect
conn = _connect(dsn, connection_factory=connection_factory, **kwasync)
psycopg2.OperationalError: timeout expired

请提供有关问题所在或如何调试的意见。

最佳答案

我也在四处寻找如何连接到 localstack 的 redshift 服务器。根据这个 github 问题,它看起来并不是真正的完整 redshift 服务器,并且目前不可能以这种方式连接(截至 2017 年 3 月,显然情况仍然如此):https://github.com/localstack/localstack/issues/28

Basic support for Redshift is added in #29 . Note that the mock functionality only covers the basic Redshift API methods (a subset of https://docs.aws.amazon.com/redshift/latest/APIReference/). The actual query capabilities (i.e., accessing Redshift via JDBC) are not supported here (at this stage it is not feasible to mock the entire query engine).

关于python - 使用 psycopg2 的 aws localstack redshift 连接问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46462006/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com