【发布时间】:2020-07-29 12:18:41
【问题描述】:
我是 python 新手,并遵循 existing_post 的答案,我正在尝试从 amazon S3 读取 json 文件,如下所示:
import boto3
import os
BUCKET = 'my_bucket'
FILE_TO_READ = 'file.json'
client = boto3.client('s3',
aws_access_key_id=os.environ.my_key,
aws_secret_access_key=os.environ.my_secret_key
)
result = client.get_object(Bucket=BUCKET, Key='file')
text = result["Body"].read().decode()
print(text['key']) # Use your desired JSON Key for your value
但是我收到以下错误:
NoSuchKey: An error occurred (NoSuchKey) when calling the GetObject operation: The specified key does not exist.
谁能告诉我我做错了什么?
【问题讨论】: