我想从官方教程中运行示例代码(tasks.py):
from celery import Celery
app = Celery('tasks', broker='amqp://guest@localhost//')
@app.task
def add(x, y): return x + y
我使用了命令“celery -A task worker --loglevel = info”,如教程中所示。 但是,当我执行此命令时,python会抛出UnicodeDecodeError:
C:\kaznmu\virtualenvs\example\Scripts>celery -A tasks worker --loglevel=info
Traceback (most recent call last):
File "C:\kaznmu\virtualenvs\example\Scripts\celery-script.py", line 9, in <mod
ule>
load_entry_point('celery==3.1.8', 'console_scripts', 'celery')()
File "C:\kaznmu\virtualenvs\example\lib\site-packages\celery\__main__.py", lin
e 30, in main
main()
File "C:\kaznmu\virtualenvs\example\lib\site-packages\celery\bin\celery.py", l
ine 80, in main
cmd.execute_from_commandline(argv)
File "C:\kaznmu\virtualenvs\example\lib\site-packages\celery\bin\celery.py", l
ine 746, in execute_from_commandline
super(CeleryCommand, self).execute_from_commandline(argv)))
File "C:\kaznmu\virtualenvs\example\lib\site-packages\celery\bin\base.py", lin
e 308, in execute_from_commandline
return self.handle_argv(self.prog_name, argv[1:])
File "C:\kaznmu\virtualenvs\example\lib\site-packages\celery\bin\celery.py", l
ine 738, in handle_argv
return self.execute(command, argv)
File "C:\kaznmu\virtualenvs\example\lib\site-packages\celery\bin\celery.py", l
ine 692, in execute
).run_from_argv(self.prog_name, argv[1:], command=argv[0])
File "C:\kaznmu\virtualenvs\example\lib\site-packages\celery\bin\worker.py", l
ine 175, in run_from_argv
return self(*args, **options)
File "C:\kaznmu\virtualenvs\example\lib\site-packages\celery\bin\base.py", lin
e 271, in __call__
ret = self.run(*args, **kwargs)
File "C:\kaznmu\virtualenvs\example\lib\site-packages\celery\bin\worker.py", l
ine 195, in run
hostname = self.simple_format(default_nodename(hostname))
File "C:\kaznmu\virtualenvs\example\lib\site-packages\celery\bin\base.py", lin
e 569, in simple_format
return self._simple_format(s, socket.gethostname(), **extra)
File "C:\kaznmu\virtualenvs\example\lib\site-packages\celery\bin\base.py", lin
e 574, in _simple_format
name, _, domain = host.partition('.')
UnicodeDecodeError: 'ascii' codec can't decode byte 0xcf in position 5: ordinal
not in range(128)
答案 0 :(得分:1)
问题是电脑名称中的俄文字符。通过重命名pc名解决。