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

SignatureDoesNotMatch when calling PutObject #262

Closed
sleibrock opened this issue Jan 31, 2017 · 2 comments
Closed

SignatureDoesNotMatch when calling PutObject #262

sleibrock opened this issue Jan 31, 2017 · 2 comments

Comments

@sleibrock
Copy link

Hi, I'm currently using django-storages in conjunction with Amazon S3 to upload images from a Django application running on Heroku. I added the setting vars as per the docpage here, which leads to an error saying to use AWS4-HMAC-SHA256 when trying to do python manage.py collectstatic.

Using sdeleeuw's instructions here changes the request to use v4 authentication, but now it's giving me a SignatureDoesNotMatch error. However, I can perfectly upload files with boto3 with my current credentials and with v4 authentication in a script like this:

from sys import argv
import boto3
from botocore.client import Config

def main(fname):
    s3 = boto3.client('s3', 'us-west-2', config=Config(s3={"addressing_style":" path"}, signature_version="s3v4"))
    s3.upload_file(fname, "my-bucket", fname)

if __name__ == "__main__":
    if len(argv) > 1:
        for f in argv[1:]:
            main(f)

Here is my output log which doesn't really tell much of a story

  File "C:\Users\sleibrock\AppData\Local\Programs\Python\Python35\lib\site-packages\boto3\s3\inject.py", line 509, in object_upload_fileobj
    ExtraArgs=ExtraArgs, Callback=Callback, Config=Config)
  File "C:\Users\sleibrock\AppData\Local\Programs\Python\Python35\lib\site-packages\boto3\s3\inject.py", line 427, in upload_fileobj
    return future.result()
  File "C:\Users\sleibrock\AppData\Local\Programs\Python\Python35\lib\site-packages\s3transfer\futures.py", line 73, in result
    return self._coordinator.result()
  File "C:\Users\sleibrock\AppData\Local\Programs\Python\Python35\lib\site-packages\s3transfer\futures.py", line 233, in result
    raise self._exception
  File "C:\Users\sleibrock\AppData\Local\Programs\Python\Python35\lib\site-packages\s3transfer\tasks.py", line 126, in __call__
    return self._execute_main(kwargs)
  File "C:\Users\sleibrock\AppData\Local\Programs\Python\Python35\lib\site-packages\s3transfer\tasks.py", line 150, in _execute_main
    return_value = self._main(**kwargs)
  File "C:\Users\sleibrock\AppData\Local\Programs\Python\Python35\lib\site-packages\s3transfer\upload.py", line 679, in _main
    client.put_object(Bucket=bucket, Key=key, Body=body, **extra_args)
  File "C:\Users\sleibrock\AppData\Local\Programs\Python\Python35\lib\site-packages\botocore\client.py", line 253, in _api_call
    return self._make_api_call(operation_name, kwargs)
  File "C:\Users\sleibrock\AppData\Local\Programs\Python\Python35\lib\site-packages\botocore\client.py", line 543, in _make_api_call
    raise error_class(parsed_response, operation_name)
botocore.exceptions.ClientError: An error occurred (SignatureDoesNotMatch) when calling the PutObject operation: The request signature we calculated does not match the signature you provided. Check your key and signing method.

Has anyone run into this problem with Heroku/S3/Django before and have a solution? Are there any settings that can be changed to fix this issue? I can post more info as needed, thank you.

@ghost
Copy link

ghost commented Apr 28, 2017

If you solved it, would you care to share how?

@sleibrock
Copy link
Author

It's stupidity on my part. In my Django project I had a blank file to keep a folder in my Git tracker to run the project. You can't generate a signature for a blank file that has no bytes written to it, so I wrote one character to the file, saved it and it worked without an issue.

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

1 participant