为什么我会收到“SyntaxError:非 ASCII 字符 '\xa3'”当运行 celeryd 时?
我正在尝试使用 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这不是编码问题。看看哪个文件有编码问题:
看起来 celery 正在尝试将您的 CELERYD 变量解析为 python 文件,尽管它实际上是 python 二进制文件。尝试从 CELERYD 变量声明的开头删除 python 二进制字符串。
It's not an encoding issue. Take a look at what file has the encoding issue:
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.
感谢 @gravitron 和 @Wooble 的提示,我通过将以下内容添加到我的 celeryd 配置中解决了这个问题:
Thanks to @gravitron and @Wooble's hints, I solved this by adding the following to my celeryd config: