简体   繁体   English

无法使用 django 访问 S3 存储桶:ValueError: Invalid endpoint

[英]Unable to access the S3 bucket with django: ValueError: Invalid endpoint

I'm trying to integrate S3 Bucket with my django application.我正在尝试将 S3 Bucket 与我的 django 应用程序集成。 But always getting this error.但总是得到这个错误。

raise ValueError("Invalid endpoint: %s" % endpoint_url)
ValueError: Invalid endpoint: <bucket_name>.s3.amazonaws.com

These are my settings.py configurations这些是我的 settings.py 配置

    AWS_ACCESS_KEY_ID = config('STATIC_ACCESS_KEY_ID')
    AWS_SECRET_ACCESS_KEY = config('STATIC_SECRET_KEY')
    AWS_S3_REGION_NAME = config('AWS_REGION')
    AWS_STORAGE_BUCKET_NAME = config('STATIC_BUCKET_NAME')
    AWS_S3_ENDPOINT_URL =  '%s.s3.amazonaws.com' % AWS_STORAGE_BUCKET_NAME
    AWS_S3_OBJECT_PARAMETERS = {
        'CacheControl': 'max-age=86400',
    }

AWS_LOCATION = 'static'
AWS_DEFAULT_ACL = 'public-read'

STATICFILES_STORAGE = 'storages.backends.s3boto3.S3Boto3Storage'
STATIC_URL =  'https://%s/%s/' % (AWS_S3_ENDPOINT_URL, AWS_LOCATION)

I have referred the answers here, ValueError: Invalid endpoint: https://s3..amazonaws.com我在这里提到了答案, ValueError: Invalid endpoint: https://s3..amazonaws.com

Region is set correct.区域设置正确。

The problem was because you didn't allow your s3 bucket to be accessible.问题是因为您不允许访问您的 s3 存储桶。 Please learn How to add Bucket policy and permissions for public access .请了解如何为公共访问添加存储桶策略和权限

And in your settings.py file.在你的 settings.py 文件中。 I added my Configurations like this:我添加了这样的配置:

AWS_ACCESS_KEY_ID = 'Your Access Key Id'
AWS_SECRET_ACCESS_KEY = 'Your Secret Key id'
""""""""""
""""""""""
""""""""""

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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