小编use*_*789的帖子

从 S3 读取 JSON

我是 python 新手,按照现有帖子的答案,我尝试从 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  
Run Code Online (Sandbox Code Playgroud)

但是我收到以下错误:

NoSuchKey: An error occurred (NoSuchKey) when calling the GetObject operation: The specified key does not exist.
Run Code Online (Sandbox Code Playgroud)

有人可以告诉我我做错了什么吗?

python amazon-s3

2
推荐指数
1
解决办法
5815
查看次数

标签 统计

amazon-s3 ×1

python ×1