DRF和芹菜:filenotfounderror:[errno 2]没有此类文件或目录

发布于 2025-02-04 04:01:41 字数 595 浏览 2 评论 0原文

这在我的本地部署上正常工作,但在云部署上效果不佳。

with open(file_path, "wb+") as fp:
    for chunk in file:
        fp.write(chunk)

result = upload.delay(name, file_path)

在另一个文件中:

@shared_task
def upload(name, file_path):

    path = Path(path_tmp)
    if os.path.isfile(path):
        do something

错误是

不是路径/媒体/介质/rawfiles/file.png”, FILENOTFOUNDERROR:[ERRNO 2]没有此类文件或目录

当我在docker中导航到 - > /mediafiles/rawfiles,该文件在那里并且具有大小。

我正在使用drf->芹菜 - > Django。

有人可以帮助为什么云部署无法找到该文件?

This works fine on my local deployment but on the cloud deployement it does not.

with open(file_path, "wb+") as fp:
    for chunk in file:
        fp.write(chunk)

result = upload.delay(name, file_path)

In a different file:

@shared_task
def upload(name, file_path):

    path = Path(path_tmp)
    if os.path.isfile(path):
        do something

The error is

Not a path /mediafiles/rawfiles/file.png",
FileNotFoundError: [Errno 2] No such file or directory

When I navigate in the docker to -> /mediafiles/rawfiles, the file is there and has a size.

I am using DRF -> Celery -> Django.

Can someone help why the cloud deployment is not able to find the file?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

鹤舞 2025-02-11 04:01:42

当您使用@shared_task将任务委派给芹菜工人并尝试访问文件系统时,它会尝试在工作机器上获取此文件。
因此,您需要使用文件或将目标文件复制到Worker Machine上的机器上执行此任务。

When you delegate task to celery worker with @shared_task and try to get access to the filesystem, it try to get this file on the worker machine.
So you need to execute this task on machine with a file or copy target file to worker machine.

我ぃ本無心為│何有愛 2025-02-11 04:01:42

我将 workdir 添加到start CMD,然后效果很好。

celery -A tasks --workdir=. worker ...

希望有帮助。

I add workdir to the start cmd, then it works well.

celery -A tasks --workdir=. worker ...

Hope that helps.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文