python - 使用 Python 访问 AWS Redshift
问题描述
我正在尝试运行 aws redshift 代码以便使用 python 连接数据库。我正在尝试运行 aws redshift 文档中给出的给定示例代码。在运行代码时我仍然遇到一些问题。
代码 :
import numpy
import redshift_connector
import socket
socket.getaddrinfo('localhost', 8080)
conn = redshift_connector.connect(
host='examplecluster.abc123xyz789.us-west-1.redshift.amazonaws.com',
database='dev',
user='awsuser',
password='my_password'
)
cursor: redshift_connector.Cursor = conn.cursor()
cursor.execute("create Temp table book(bookname varchar,author varchar)")
cursor.executemany("insert into book (bookname, author) values (%s, %s)",
[
('One Hundred Years of Solitude', 'Gabriel García Márquez'),
('A Brief History of Time', 'Stephen Hawking')
]
)
cursor.execute("select * from book")
result: numpy.ndarray = cursor.fetch_numpy_array()
print(result)
cursor.execute("drop table book")
conn.commit()
conn.close()
错误 :
解决方案
推荐阅读
- python - 如何在元组中用逗号替换空格?
- sql - 为什么尝试使用日期查询删除旧行时所有行都被删除
- flutter - 使用 dio 上传多图像选择器(包已过期)问题
- android - 设备旋转时如何防止edittext焦点回到第一个edittext
- flutter - 如何使用 Flutter 实现这一点?
- gcc - 运行 rhel6 构建的可执行文件时在 rhel7 机器上导入错误
- asp.net - 如果 nuget 包支持 .Net Standard 2.0,那么我们可以在 asp.net 和 asp.net 核心中使用该包吗?
- jenkins-pipeline - 如何使用 Jenkins 中的 ssh 发布将环境变量传递给远程主机
- java - AuthorizationCodeInstalledApp,意外行为
- amazon-web-services - 您可以将文件设置为隐藏在 S3 存储桶中吗?