我正在Heroku设置一个Django应用,并希望在S3上存储媒体文件。我正在使用Python's Boto module并继续遇到同样的错误:
错误:
No handler was ready to authenticate.
1 handlers were checked. ['HmacAuthV1Handler'] Check your credentials
我已尝试保存凭据
(a)在我的Heroku config file
中使用os.environ['AWS_ACCESS_KEY_ID]
(b)在我的settings.py
文件和
(c)根据文档在单独的.boto文件中。
以下是我的settings.py的相关部分,其中包含文件本身的凭据:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3', # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'.
'NAME': "os.path.join(BASE_DIR, 'db.sqlite3')", # Or path to database file if using sqlite3.
# The following settings are not used with sqlite3:
'USER': '',
'PASSWORD': '',
'HOST': '', # Empty for localhost through domain sockets or '127.0.0.1' for localhost through TCP.
'PORT': '', # Set to empty string for default.
}
}
#config for S3
DATABASES['default'] = dj_database_url.config()
SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https')
S3_BUCKET_NAME = 'companylistings'
#AWS_ACCESS_KEY_ID = 'xxxxxxxxxxxxxxx'
#AWS_SECRET_ACCESS_KEY = 'xxxxxxxxxxxxxxx'
#STATICFILES_STORAGE = 'storages.backends.s3boto.S3BotoStorage'
DEFAULT_FILE_STORAGE = 'storages.backends.s3boto.S3BotoStorage'
S3_URL = 'http://s3.amazonaws.com/%s' %S3_BUCKET_NAME
MEDIA_ROOT = '/media/'
MEDIA_URL = S3_URL + MEDIA_ROOT
STATIC_ROOT = '/static/'
STATIC_URL = S3_URL + STATIC_ROOT
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
STATICFILES_DIRS = (
os.path.join(BASE_DIR, 'static'),
)
答案 0 :(得分:0)
检查您的水桶设置:
S3_BUCKET_NAME
我的工作配置是:
AWS_STORAGE_BUCKET_NAME
试试这个!
我的完整配置是:
DEFAULT_FILE_STORAGE = 'storages.backends.s3boto.S3BotoStorage'
AWS_ACCESS_KEY_ID = 'PRIVATE'
AWS_SECRET_ACCESS_KEY = 'PRIVATE'
AWS_STORAGE_BUCKET_NAME = 'PRIVATE'
答案 1 :(得分:0)
如果是在Windows上,请按照:
安装:pip install awscli
打开cmd并输入:
$ aws configure
AWS Access Key ID: 'your Access Key ID'
AWS Secret Access Key: 'your Secret Access Key'
Default region name: us-east-1
Default output format: json
$ manage.py shell
>>import boto
>>s3 = boto.connect_s3()
未显示任何错误消息。它完成了