Skip to main content
 首页 » 编程设计

python之使用 django-storages 和 s3 时出现 [Errno 32] Broken pipe

2025年05月04日37lexus

我在使用 s3 的 django-storages 时遇到了问题。一切都使用 boto(创建和读回文件)工作,因此它与凭据无关。

我在 settings.py 中有以下键:

DEFAULT_FILE_STORAGE = 'storages.backends.s3boto.S3BotoStorage' 
AWS_ACCESS_KEY_ID = '...' 
AWS_SECRET_ACCESS_KEY = '...' 
AWS_STORAGE_BUCKET_NAME = 'sff-dev' 

我有以下模型:

class Document(models.Model): 
    title = models.CharField(max_length=100) 
    document = models.FileField(upload_to='documents') 

我不确定我应该为 upload_to 使用什么,如果有的话。我也试过 '/'。

我尝试了各种方法,例如设置 AWS_QUERYSTRING_AUTH = False 和 AWS_S3_SECURE_URLS = False,但没有任何效果。

请您参考如下方法:

我也在研究这个。在 these 中找到了我的解决方案answers

tl;dr:是我从 django-storages 切换到 django-storages-redux 并将以下内容添加到我的 settings.py:

AWS_S3_HOST = "s3-us-west-2.amazonaws.com"