fugue / credstash

A little utility for managing credentials in the cloud
Apache License 2.0
2.06k stars 214 forks source link

AttributeError: 'NoCredentialsError' object has no attribute 'message' #224

Open fxcoudert opened 6 years ago

fxcoudert commented 6 years ago

While running credstash with the latest version of all its dependencies on Python 3 (as part of Homebrew testing), there is an error that it not caught correctly:

$ credstash put test test                                     
Traceback (most recent call last):
  File "/usr/local/Cellar/credstash/1.15.0_1/libexec/bin/credstash.py", line 79, in generate_key_data
    KeyId=self.key_id, EncryptionContext=self.encryption_context, NumberOfBytes=number_of_bytes
  File "/usr/local/Cellar/credstash/1.15.0_1/libexec/lib/python3.7/site-packages/botocore/client.py", line 320, in _api_call
    return self._make_api_call(operation_name, kwargs)
  File "/usr/local/Cellar/credstash/1.15.0_1/libexec/lib/python3.7/site-packages/botocore/client.py", line 610, in _make_api_call
    operation_model, request_dict)
  File "/usr/local/Cellar/credstash/1.15.0_1/libexec/lib/python3.7/site-packages/botocore/endpoint.py", line 102, in make_request
    return self._send_request(request_dict, operation_model)
  File "/usr/local/Cellar/credstash/1.15.0_1/libexec/lib/python3.7/site-packages/botocore/endpoint.py", line 132, in _send_request
    request = self.create_request(request_dict, operation_model)
  File "/usr/local/Cellar/credstash/1.15.0_1/libexec/lib/python3.7/site-packages/botocore/endpoint.py", line 116, in create_request
    operation_name=operation_model.name)
  File "/usr/local/Cellar/credstash/1.15.0_1/libexec/lib/python3.7/site-packages/botocore/hooks.py", line 356, in emit
    return self._emitter.emit(aliased_event_name, **kwargs)
  File "/usr/local/Cellar/credstash/1.15.0_1/libexec/lib/python3.7/site-packages/botocore/hooks.py", line 228, in emit
    return self._emit(event_name, kwargs)
  File "/usr/local/Cellar/credstash/1.15.0_1/libexec/lib/python3.7/site-packages/botocore/hooks.py", line 211, in _emit
    response = handler(**kwargs)
  File "/usr/local/Cellar/credstash/1.15.0_1/libexec/lib/python3.7/site-packages/botocore/signers.py", line 90, in handler
    return self.sign(operation_name, request)
  File "/usr/local/Cellar/credstash/1.15.0_1/libexec/lib/python3.7/site-packages/botocore/signers.py", line 157, in sign
    auth.add_auth(request)
  File "/usr/local/Cellar/credstash/1.15.0_1/libexec/lib/python3.7/site-packages/botocore/auth.py", line 356, in add_auth
    raise NoCredentialsError
botocore.exceptions.NoCredentialsError: Unable to locate credentials

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/bin/credstash", line 11, in <module>
    load_entry_point('credstash==1.15.0', 'console_scripts', 'credstash')()
  File "/usr/local/Cellar/credstash/1.15.0_1/libexec/bin/credstash.py", line 916, in main
    putSecretAction(args, region, **session_params)
  File "/usr/local/Cellar/credstash/1.15.0_1/libexec/bin/credstash.py", line 246, in func_wrapper
    return func(*args, **kwargs)
  File "/usr/local/Cellar/credstash/1.15.0_1/libexec/bin/credstash.py", line 387, in putSecretAction
    **session_params):
  File "/usr/local/Cellar/credstash/1.15.0_1/libexec/bin/credstash.py", line 297, in putSecret
    digest_method=digest,
  File "/usr/local/Cellar/credstash/1.15.0_1/libexec/bin/credstash.py", line 613, in seal_aes_ctr_legacy
    key, encoded_key = key_service.generate_key_data(64)
  File "/usr/local/Cellar/credstash/1.15.0_1/libexec/bin/credstash.py", line 82, in generate_key_data
    raise KmsError("Could not generate key using KMS key %s (Detail: %s)" % (self.key_id, e.message))
AttributeError: 'NoCredentialsError' object has no attribute 'message'
rseuchter commented 4 years ago

Exceptions no longer have a message attribute in Python 3. See PEP 352. I just hit a similar issue running some code in Python 3 that's trying to access message. I found this bug you opened during my research about the reason of the problem.

Unfortunately neither the Python 2 docs nor the Python 3.7 docs mention this so I found it rather difficult to find.