heroku上的django:访问s3媒体以读取和处理媒体文件时,芹菜工作者被禁止使用403

问题描述 投票:0回答:1

我真的很坚持这一点,因为我不确定从哪里开始:

我的Django项目允许用户上传电子表格,然后该应用处理并汇总上传的数据。

该文件使用标准格式和带有FileField的Django模型上传到MEDIA_URL。上传后,芹菜工作者将访问该文件并进行处理,然后将输出写入另一个模型。

这在本地可以正常使用,但无法在生产环境中使用。我正在部署到heroku,并使用cookiecutter-django项目模板。我已经设置了s3存储桶,并且正在使用django-storages库。

文件上传没有问题-我可以在Django管理员以及s3存储桶中访问和删除它们。

但是,当芹菜工作者尝试读取文件时,我得到了HTTP Error 403: Forbidden。我不确定如何解决此问题,因为我不确定堆栈的哪一部分包含我的错误。是我的tasks.py模块,heroku:redis插件还是settings.py模块?

django heroku amazon-s3 celery django-media
1个回答
0
投票

必须告诉celery从何处获取其配置(要使用哪个设置文件)。部署时,我没有将配置更新为生产设置。

这是我的固定celery_app.py

import os

from celery import Celery

# set the default Django settings module for the 'celery' program.
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "config.settings.production")

app = Celery("<project_name>")

# Using a string here means the worker doesn't have to serialize
# the configuration object to child processes.
# - namespace='CELERY' means all celery-related configuration keys
#   should have a `CELERY_` prefix.
app.config_from_object("django.conf:settings", namespace="CELERY")

# Load task modules from all registered Django app configs.
app.autodiscover_tasks()
© www.soinside.com 2019 - 2024. All rights reserved.