Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

KeyError if listing bucket with no items returned #76

Closed
simonw opened this issue Aug 3, 2022 · 0 comments
Closed

KeyError if listing bucket with no items returned #76

simonw opened this issue Aug 3, 2022 · 0 comments
Labels
bug Something isn't working

Comments

@simonw
Copy link
Owner

simonw commented Aug 3, 2022

Just saw this error:

% s3-credentials list-bucket my-bucket-name -a /tmp/creds.json --prefix some-prefix/
Traceback (most recent call last):
  File "/Users/simon/.local/share/virtualenvs/s3-credentials-J8M1ChYK/bin/s3-credentials", line 33, in <module>
    sys.exit(load_entry_point('s3-credentials', 'console_scripts', 's3-credentials')())
  File "/Users/simon/.local/share/virtualenvs/s3-credentials-J8M1ChYK/lib/python3.10/site-packages/click/core.py", line 1128, in __call__
    return self.main(*args, **kwargs)
  File "/Users/simon/.local/share/virtualenvs/s3-credentials-J8M1ChYK/lib/python3.10/site-packages/click/core.py", line 1053, in main
    rv = self.invoke(ctx)
  File "/Users/simon/.local/share/virtualenvs/s3-credentials-J8M1ChYK/lib/python3.10/site-packages/click/core.py", line 1659, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/Users/simon/.local/share/virtualenvs/s3-credentials-J8M1ChYK/lib/python3.10/site-packages/click/core.py", line 1395, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/Users/simon/.local/share/virtualenvs/s3-credentials-J8M1ChYK/lib/python3.10/site-packages/click/core.py", line 754, in invoke
    return __callback(*args, **kwargs)
  File "/Users/simon/Dropbox/Development/s3-credentials/s3_credentials/cli.py", line 896, in list_bucket
    output(
  File "/Users/simon/Dropbox/Development/s3-credentials/s3_credentials/cli.py", line 1103, in output
    for line in stream_indented_json(iterator):
  File "/Users/simon/Dropbox/Development/s3-credentials/s3_credentials/cli.py", line 1112, in stream_indented_json
    next(next_iter, None)
  File "/Users/simon/Dropbox/Development/s3-credentials/s3_credentials/cli.py", line 1135, in paginate
    yield from response[list_key]
KeyError: 'Contents'

This was because there were no files to return. I used the debugger and got this for response:

{'EncodingType': 'url',
 'IsTruncated': False,
 'KeyCount': 0,
 'MaxKeys': 1000,
 'Name': 'my-bucket-name',
 'Prefix': 'team-41/',
 'ResponseMetadata': {'HTTPHeaders': {'content-type': 'application/xml',
                                      'date': 'Wed, 03 Aug 2022 03:49:30 GMT',
                                      'server': 'AmazonS3',
                                      'transfer-encoding': 'chunked',
                                      'x-amz-bucket-region': 'us-east-1',
                                      'x-amz-id-2': 'jbmLLH0cyv7j9O8fjIj4YU8oQT5GDeeKRr88wrZ9oFPh2FASNZ4azxRMCUaDPc9ZlOblSl8y7/Y=',
                                      'x-amz-request-id': 'JQJWTX2M6GSYJWX1'},
                      'HTTPStatusCode': 200,
                      'HostId': 'jbmLLH0cyv7j9O8fjIj4YU8oQT5GDeeKRr88wrZ9oFPh2FASNZ4azxRMCUaDPc9ZlOblSl8y7/Y=',
                      'RequestId': 'JQJWTX2M6GSYJWX1',
                      'RetryAttempts': 0}}
@simonw simonw added the bug Something isn't working label Aug 3, 2022
@simonw simonw closed this as completed in 30e07d3 Aug 12, 2022
simonw added a commit that referenced this issue Aug 12, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant