title: how to fix key error in listing content from a s3 bucket in aws?
body: <p>I have following piece of code, that utilizes list_objects_v2 from boto3. I get an error =&gt; keyError : 'Contents'. I am assuming if name of the file i'm passing doesn't exist , it throws this error.</p>
  <pre><code>import boto3
  s3_R = boto3.client('s3')
  s3_b = s3_R.Bucket(&quot;MyBucket&quot;)
  
  response = s3_R.list_objects_v2(Bucket=s3_b, Prefix='myfilename')
  for obj in response['contents']:
     file = obj['key']
     print(file)
  </code></pre>