为什么我会收到“SyntaxError:非 ASCII 字符 '\xa3'”当运行 celeryd 时?

发布于 2024-12-27 02:24:31 字数 1021 浏览 2 评论 0原文

我正在尝试使用 Django & 运行 celeryd Ubuntu 上的 Virtualenv,我收到此错误:

celeryd-multi v2.4.5
> Starting nodes...
    > celery.heron:   File "/sites/.virtualenvs/myproject/bin/python", line 1
SyntaxError: Non-ASCII character '\xa3' in file /sites/.virtualenvs/myproject/bin/python on line 2, but no encoding declared; see http://www.python.org/peps/pep-0263.html for details
* Child terminated with failure code 1
FAILED

我认为这是一个编码问题,但不确定在哪里。我将 # -*-coding: utf-8 -*- 添加到我的 celeryd-multi 脚本、manage.py 脚本以及包含任务代码的实际 .py 文件中,但这并没有解决问题。

这是我的 /etc/default/celeryd 配置文件:

CELERYD="/sites/.virtualenvs/myproject/bin/python /sites/dev.myproject.co/code/myproject/manage.py celeryd"

CELERYD_CHDIR="/sites/dev.myproject.co/code/myproject"

DJANGO_SETTINGS_MODULE="settings"

CELERYD_OPTS="-v 2 -B -s celery -E"

CELERYD_LOG_FILE="/sites/dev.myproject.co/logs/celery.log"

CELERYD_USER="www-data"

CELERYD_GROUP="www-data"

我缺少什么?

I am trying to run celeryd with Django & Virtualenv on Ubuntu and I am getting this error:

celeryd-multi v2.4.5
> Starting nodes...
    > celery.heron:   File "/sites/.virtualenvs/myproject/bin/python", line 1
SyntaxError: Non-ASCII character '\xa3' in file /sites/.virtualenvs/myproject/bin/python on line 2, but no encoding declared; see http://www.python.org/peps/pep-0263.html for details
* Child terminated with failure code 1
FAILED

I thought it was an encoding issue, but not sure where. I added # -*- coding: utf-8 -*- to my celeryd-multi script, as well as to my manage.py script, and the actual .py file that has the task code, but that didn't solve it.

This is my /etc/default/celeryd config file:

CELERYD="/sites/.virtualenvs/myproject/bin/python /sites/dev.myproject.co/code/myproject/manage.py celeryd"

CELERYD_CHDIR="/sites/dev.myproject.co/code/myproject"

DJANGO_SETTINGS_MODULE="settings"

CELERYD_OPTS="-v 2 -B -s celery -E"

CELERYD_LOG_FILE="/sites/dev.myproject.co/logs/celery.log"

CELERYD_USER="www-data"

CELERYD_GROUP="www-data"

What am I missing?

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

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

发布评论

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

评论(2

流云如水 2025-01-03 02:24:31

这不是编码问题。看看哪个文件有编码问题:

/sites/.virtualenvs/myproject/bin/python

看起来 celery 正在尝试将您的 CELERYD 变量解析为 python 文件,尽管它实际上是 python 二进制文件。尝试从 CELERYD 变量声明的开头删除 python 二进制字符串。

It's not an encoding issue. Take a look at what file has the encoding issue:

/sites/.virtualenvs/myproject/bin/python

It looks like celery is trying to parse your CELERYD variable as a python file, despite it actually being the python binary. Try removing the python binary string from the start of the CELERYD variable declaration.

小姐丶请自重 2025-01-03 02:24:31

感谢 @gravitron 和 @Wooble 的提示,我通过将以下内容添加到我的 celeryd 配置中解决了这个问题:

# Python interpreter from environment.
ENV_PYTHON="/sites/.virtualenvs/myproject/bin/python"

# How to call "manage.py celeryd_multi"
CELERYD_MULTI="$ENV_PYTHON $CELERYD_CHDIR/manage.py celeryd_multi"

# How to call "manage.py celeryctl"
CELERYCTL="$ENV_PYTHON $CELERYD_CHDIR/manage.py celeryctl"

Thanks to @gravitron and @Wooble's hints, I solved this by adding the following to my celeryd config:

# Python interpreter from environment.
ENV_PYTHON="/sites/.virtualenvs/myproject/bin/python"

# How to call "manage.py celeryd_multi"
CELERYD_MULTI="$ENV_PYTHON $CELERYD_CHDIR/manage.py celeryd_multi"

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