LoginSignup
0
0

More than 1 year has passed since last update.

An error occurred (NoSuchKey) when calling the GetObject operation: The specified key does not exist.

Last updated at Posted at 2021-11-04

エラーの訳

指定されたキーは存在しないよ

コード

bucket_name = 'xxx'
object_key_name = 'xxx.json'
s3 = boto3.resource(
                's3',
                region_name='ap-northeast-1',
                aws_access_key_id = 'xxx',
                aws_secret_access_key = 'xxx',
            )

bucket = s3.Bucket(bucket_name)
obj = bucket.Object(object_key_name)

response = obj.get()
body = response['Body'].read()

json.loads(body.decode('utf-8'))

エラー

An error occurred (NoSuchKey) when calling the GetObject operation: The specified key does not exist.

解決方法

解決方法は、キーを見直すこと。
キー≒パス≒ディレクトリ
したがって、ディレクトリを見直すこと。一文字違ってもダメ。

エラー発生原因は非常にシンプル。ディレクトリが違うから。
ここでいうと、
object_key_name
の事になる。
例えば
aaa/bbb/ccc/ddd.json
を持ってきたいのに
aaa/bbb/ccc/eee.json
を指定していると上記のエラーが発生する。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0