Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
2.4k views
in Technique[技术] by (71.8m points)

django - 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

enter image description here

Is there anything I am missing now?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

~/.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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
...