python - 为什么我在使用 Python boto s3 select_object_content 时出现此错误?

标签 python amazon-web-services amazon-s3 boto3

我想在 Windows 中运行以下代码以从 s3 对象中获取前几行:

import boto3
s3 = boto3.client('s3')
sql_stmt = """select * from s3object limit 5"""

req = s3.select_object_content(
 Bucket=bucket,
 Key=file,
 ExpressionType='SQL',
 Expression=sql_stmt,
 InputSerialization = {'CSV': {'FileHeaderInfo': 'Use', 'FieldDelimiter': ','}},
 OutputSerialization = {'CSV': {}})
它一直告诉我:
An error occurred (InvalidRequest) when calling the SelectObjectContent operation: 
S3 Transfer Acceleration is not configured on this bucket
这可能与我今年早些时候尝试测试传输加速有关(它没有奏效)。我尝试使用 aws cli 确认和禁用传输加速:
aws configure set default.s3.use_accelerate_endpoint false
我可以从 EMR 集群运行相同的代码,所以错误肯定是我的 Windows 环境本地的。如何禁用传输加速?

最佳答案

您的 boto3 应用程序是使用非默认 AWS 配置文件启动的(例如,通过 AWS_PROFILE 环境变量或 some other supported way 设置),或者您的 ~/.aws/config文件不正确。
如果使用默认配置文件,那么我会检查 ~/.aws/config看起来像这样:

[default]
region = us-east-1
s3 =
    signature_version = s3v4
    use_accelerate_endpoint = false

关于python - 为什么我在使用 Python boto s3 select_object_content 时出现此错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64557755/

相关文章:

python - 当模块名称中包含 '-' 破折号或连字符时如何导入模块?

amazon-web-services - AWS Lambda - 支持多个文件

python - 在 EMR 中运行 Jupyter 笔记本时没有名为 'pyspark' 的模块

amazon-web-services - 如何在 Terraform 中配置 CloudWatch Lambda Insights

symfony - 如何使用 symfony/gauferette/VichUploaderBundle 将文件上传到 Google Cloud Storage

python - com.amazonaws.AmazonClientException : Unable to execute HTTP request: No such host is known (spark-tunes. s3a.ap-south-1.amazonaws.com)

用于识别包含在三引号中的有效 Python 字符串的 Javascript flavor 正则表达式

Python,Pandas删除指定列中具有特定值的行

python BeautifulSoup查找span id名称而不使用string\re方法

elasticsearch - Logstash 一直在执行 s3 输入任务但从未发送输出事件