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

Exception when using an empty "secret key" string #30

Open
jamshid opened this issue Feb 18, 2017 · 1 comment
Open

Exception when using an empty "secret key" string #30

jamshid opened this issue Feb 18, 2017 · 1 comment

Comments

@jamshid
Copy link

jamshid commented Feb 18, 2017

If you get an error like this, you're creating AWS4Auth() with an empty "secret key" string.

>>> requests_aws4auth.AWS4Auth('username','', 'eu-west-1', 's3')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python2.7/site-packages/requests_aws4auth/aws4auth.py", line 246, in __init__
    self.regenerate_signing_key(secret_key=secret_key)
  File "/usr/lib/python2.7/site-packages/requests_aws4auth/aws4auth.py", line 291, in regenerate_signing_key
    secret_key = secret_key or self.signing_key.secret_key
AttributeError: 'NoneType' object has no attribute 'secret_key'

It's not something real users would want to do, but found this in testing code that previously ran with V2 Signature awsauth.S3Auth. This patch works around the error:

diff -u /usr/lib/python2.7/site-packages/requests_aws4auth/aws4auth.py~ /usr/lib/python2.7/site-packages/requests_aws4auth/aws4auth.py
--- /usr/lib/python2.7/site-packages/requests_aws4auth/aws4auth.py~	2017-02-15 19:17:02.000000000 +0000
+++ /usr/lib/python2.7/site-packages/requests_aws4auth/aws4auth.py	2017-02-18 00:18:15.425646504 +0000
@@ -288,7 +288,7 @@
                                    self.signing_key.secret_key is None):
             raise NoSecretKeyError
 
-        secret_key = secret_key or self.signing_key.secret_key
+        secret_key = secret_key or (self.signing_key and self.signing_key.secret_key) or ''
         region = region or self.region
         service = service or self.service
         date = date or self.date
@aalvrz
Copy link

aalvrz commented Jun 18, 2018

@sam-washington I am experiencing this behavior using fallback env variables in my unit tests and it's very annoying. Could we change this behavior?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants