简体   繁体   中英

boto S3ResponseError: 400 Bad Request

I'm deploying my Django application on Ubuntu of EC2 on AWS.

I finished all the jobs needed but connecting to boto.

In my settings.py

AWS_ACCESS_KEY = 'AWS_ACCESS_KEY'
AWS_SECRET_ACCESS_KEY = 'AWS_SECRET_ACCESS_KEY'
AWS_STORAGE_BUCKET_NAME = 'BUCKET-s3'
AWS_QUERYSTRING_AUTH = False
S3_URL = 'https://s3.ap-northeast-2.amazonaws.com/%s' % AWS_STORAGE_BUCKET_NAME

DEFAULT_FILE_STORAGE = 'PROJECT.s3utils.MediaS3BotoStorage'
STATICFILES_STORAGE = 'PROJECT.s3utils.StaticRootS3BotoStorage'
MEDIA_URL = S3_URL + '/media/'
STATIC_URL = S3_URL + '/static/'

MEDIA_ROOT = MEDIA_URL
STATIC_ROOT = STATIC_URL

'PROJECT.s3utils.py' is below:

from storages.backends.s3boto import S3BotoStorage
StaticRootS3BotoStorage = lambda: S3BotoStorage(location='static') # s3 directory name
class MediaS3BotoStorage(S3BotoStorage):
    location = 'media'

Finally, I need to set up configuration file for connecting boto.

Without anything, when I command 'python manage.py collectstatic' , the error shows this message :

boto.exception.NoAuthHandlerFound: No handler was ready to authenticate. 1 handlers were checked. ['HmacAuthV1Handler'] Check your credentials

So I did add configuration file at '~/.boto' as below:

[Credentials]
AWS_ACCESS_KEY_ID=AWS_ACCESS_KEY_ID
AWS_SECRET_ACCESS_KEY=AWS_SECRET_ACCESS_KEY

After creating configuration file ~/.boto, I did command 'python manage.py collectstatic'

I got an error :

boto.exception.S3ResponseError: S3ResponseError: 400 Bad Request

What I do is following the boto document : http://boto.cloudhackers.com/en/latest/getting_started.html

在此处输入图片说明

Is there anything I am missing now?

~/.boto

[Credentials]
aws_access_key_id = aws_access_key_id
aws_secret_access_key = aws_secret_access_key
[s3]
host=s3.ap-northeast-2.amazonaws.com
aws_access_key_id = aws_access_key_id
aws_secret_access_key = aws_secret_access_key

It's working with ~/.boto file above

conn = boto.connect_s3(AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, host=REGION_HOST)

必填字段-主机(s3端点)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM