我正在尝试在他们的网站(http://docs.celeryproject.org/en/latest/getting-started/first-steps-with-celery.html)上运行芹菜的启动代码,并且我在后台运行RabbitMQ服务器的实例。但是,我收到一条很长的错误消息:
>>> from celery import Celery
>>> app = Celery('tasks', broker='pyamqp://guest@localhost//')
>>> @app.task
... def add(x, y):
... return x + y
...
>>>
>>> add.delay(4, 4)
Traceback (most recent call last):
File "C:UsersAlexanderAnaconda3libsite-packageskombuutilsfunctional.py", line 36, in __call__
return self.__value__
AttributeError: 'ChannelPromise' object has no attribute '__value__'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:UsersAlexanderAnaconda3libsite-packageskombuconnection.py", line 494, in _ensured
return fun(*args, **kwargs)
File "C:UsersAlexanderAnaconda3libsite-packageskombumessaging.py", line 187, in _publish
channel = self.channel
File "C:UsersAlexanderAnaconda3libsite-packageskombumessaging.py", line 209, in _get_channel
channel = self._channel = channel()
File "C:UsersAlexanderAnaconda3libsite-packageskombuutilsfunctional.py", line 38, in __call__
value = self.__value__ = self.__contract__()
File "C:UsersAlexanderAnaconda3libsite-packageskombumessaging.py", line 224, in <lambda>
channel = ChannelPromise(lambda: connection.default_channel)
File "C:UsersAlexanderAnaconda3libsite-packageskombuconnection.py", line 819, in default_channel
self.connection
File "C:UsersAlexanderAnaconda3libsite-packageskombuconnection.py", line 802, in connection
self._connection = self._establish_connection()
File "C:UsersAlexanderAnaconda3libsite-packageskombuconnection.py", line 757, in _establish_connection
conn = self.transport.establish_connection()
File "C:UsersAlexanderAnaconda3libsite-packageskombutransportpyamqp.py", line 130, in establish_connection
conn.connect()
File "C:UsersAlexanderAnaconda3libsite-packagesamqpconnection.py", line 294, in connect
self.transport.connect()
File "C:UsersAlexanderAnaconda3libsite-packagesamqptransport.py", line 122, in connect
self.socket_settings, self.read_timeout, self.write_timeout,
File "C:UsersAlexanderAnaconda3libsite-packagesamqptransport.py", line 174, in _init_socket
self._set_socket_options(socket_settings)
File "C:UsersAlexanderAnaconda3libsite-packagesamqptransport.py", line 204, in _set_socket_options
self.sock.setsockopt(SOL_TCP, opt, val)
OSError: [WinError 10042] An unknown, invalid, or unsupported option or level was specified in a getsockopt or setsockopt call
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:UsersAlexanderAnaconda3libsite-packageskombuconnection.py", line 414, in _reraise_as_library_errors
yield
File "C:UsersAlexanderAnaconda3libsite-packageskombuconnection.py", line 515, in _ensured
reraise_as_library_errors=False,
File "C:UsersAlexanderAnaconda3libsite-packageskombuconnection.py", line 405, in ensure_connection
callback)
File "C:UsersAlexanderAnaconda3libsite-packageskombuutilsfunctional.py", line 333, in retry_over_time
return fun(*args, **kwargs)
File "C:UsersAlexanderAnaconda3libsite-packageskombuconnection.py", line 261, in connect
return self.connection
File "C:UsersAlexanderAnaconda3libsite-packageskombuconnection.py", line 802, in connection
self._connection = self._establish_connection()
File "C:UsersAlexanderAnaconda3libsite-packageskombuconnection.py", line 757, in _establish_connection
conn = self.transport.establish_connection()
File "C:UsersAlexanderAnaconda3libsite-packageskombutransportpyamqp.py", line 130, in establish_connection
conn.connect()
File "C:UsersAlexanderAnaconda3libsite-packagesamqpconnection.py", line 294, in connect
self.transport.connect()
File "C:UsersAlexanderAnaconda3libsite-packagesamqptransport.py", line 122, in connect
self.socket_settings, self.read_timeout, self.write_timeout,
File "C:UsersAlexanderAnaconda3libsite-packagesamqptransport.py", line 174, in _init_socket
self._set_socket_options(socket_settings)
File "C:UsersAlexanderAnaconda3libsite-packagesamqptransport.py", line 204, in _set_socket_options
self.sock.setsockopt(SOL_TCP, opt, val)
OSError: [WinError 10042] An unknown, invalid, or unsupported option or level was specified in a getsockopt or setsockopt call
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:UsersAlexanderAnaconda3libsite-packagesceleryapptask.py", line 412, in delay
return self.apply_async(args, kwargs)
File "C:UsersAlexanderAnaconda3libsite-packagesceleryapptask.py", line 535, in apply_async
**options
File "C:UsersAlexanderAnaconda3libsite-packagesceleryappbase.py", line 737, in send_task
amqp.send_task_message(P, name, message, **options)
File "C:UsersAlexanderAnaconda3libsite-packagesceleryappamqp.py", line 558, in send_task_message
**properties
File "C:UsersAlexanderAnaconda3libsite-packageskombumessaging.py", line 181, in publish
exchange_name, declare,
File "C:UsersAlexanderAnaconda3libsite-packageskombuconnection.py", line 527, in _ensured
errback and errback(exc, 0)
File "C:UsersAlexanderAnaconda3libcontextlib.py", line 77, in __exit__
self.gen.throw(type, value, traceback)
File "C:UsersAlexanderAnaconda3libsite-packageskombuconnection.py", line 419, in _reraise_as_library_errors
sys.exc_info()[2])
File "C:UsersAlexanderAnaconda3libsite-packagesvinefive.py", line 175, in reraise
raise value.with_traceback(tb)
File "C:UsersAlexanderAnaconda3libsite-packageskombuconnection.py", line 414, in _reraise_as_library_errors
yield
File "C:UsersAlexanderAnaconda3libsite-packageskombuconnection.py", line 515, in _ensured
reraise_as_library_errors=False,
File "C:UsersAlexanderAnaconda3libsite-packageskombuconnection.py", line 405, in ensure_connection
callback)
File "C:UsersAlexanderAnaconda3libsite-packageskombuutilsfunctional.py", line 333, in retry_over_time
return fun(*args, **kwargs)
File "C:UsersAlexanderAnaconda3libsite-packageskombuconnection.py", line 261, in connect
return self.connection
File "C:UsersAlexanderAnaconda3libsite-packageskombuconnection.py", line 802, in connection
self._connection = self._establish_connection()
File "C:UsersAlexanderAnaconda3libsite-packageskombuconnection.py", line 757, in _establish_connection
conn = self.transport.establish_connection()
File "C:UsersAlexanderAnaconda3libsite-packageskombutransportpyamqp.py", line 130, in establish_connection
conn.connect()
File "C:UsersAlexanderAnaconda3libsite-packagesamqpconnection.py", line 294, in connect
self.transport.connect()
File "C:UsersAlexanderAnaconda3libsite-packagesamqptransport.py", line 122, in connect
self.socket_settings, self.read_timeout, self.write_timeout,
File "C:UsersAlexanderAnaconda3libsite-packagesamqptransport.py", line 174, in _init_socket
self._set_socket_options(socket_settings)
File "C:UsersAlexanderAnaconda3libsite-packagesamqptransport.py", line 204, in _set_socket_options
self.sock.setsockopt(SOL_TCP, opt, val)
kombu.exceptions.OperationalError: [WinError 10042] An unknown, invalid, or unsupported option or level was specified in a getsockopt or setsockopt call
github上有一个未解决的问题,其中看到了相同的操作系统错误:
https://github.com/celery/py-amqp/issues/130
有人在关于该问题的评论中建议通过将amqp版本降级到2.1.3来暂时解决
降级要采取的步骤:
- 使用
$ pip uninstall amqp
卸载 amqp。 - 使用
$ pip install -Iv amqp==2.1.3
安装 amqp 。