0

我有一个简单的功能,tasks.py其中使用CutyCaptxvfb-run 截取网页的屏幕截图。屏幕截图被视为通过OSpython 库提供的命令。我还有另一个call.py调用该函数的脚本。

当我将它作为常规函数运行时call.py(它访问网页,截取屏幕截图并将其保存在本地文件夹中),此函数运行良好,但是当我添加.delay它并在 celery 中运行它时,我收到以下错误:

[2016-12-21 13:17:52,649: INFO/MainProcess] Connected to amqp://*******************************
[2016-12-21 13:17:52,851: INFO/MainProcess] mingle: searching for neighbors
[2016-12-21 13:17:54,665: INFO/MainProcess] mingle: all alone
[2016-12-21 13:17:55,469: INFO/MainProcess] celery@myubuntucomputer ready.
[2016-12-21 13:18:01,470: CRITICAL/MainProcess] Can't decode message body: ContentDisallowed(u'Refusing to deserialize untrusted content of type pickle (application/x-python-serialize)',) [type:'application/x-python-serialize' encoding:'binary' headers:{}]

body: '\x80\x02}q\x01(U\x07expiresq\x02NU\x03utcq\x03\x88U\x04argsq\x04U http://www.reddit.com/q\x05\x85q\x06U\x05chordq\x07NU\tcallbacksq\x08NU\x08errbacksq\tNU\x07tasksetq\nNU\x02idq\x0bU$518f96eb-e132-4261-984b-255fcb5b2252q\x0cU\x07retriesq\rK\x00U\x04taskq\x0eU\x15tasks.take_screenshotq\x0fU\ttimelimitq\x10NN\x86U\x03etaq\x11NU\x06kwargsq\x12}q\x13U\nserializerq\x14U\x06pickleq\x15su.' (278b)
Traceback (most recent call last):
  File "/usr/local/Desktop/celery/venv/local/lib/python2.7/site-packages/celery/worker/consumer/consumer.py", line 551, in on_task_received
    payload = message.decode()
  File "/usr/local/Desktop/celery/venv/local/lib/python2.7/site-packages/kombu/message.py", line 192, in decode
    self._decoded_cache = self._decode()
  File "/usr/local/Desktop/celery/venv/local/lib/python2.7/site-packages/kombu/message.py", line 197, in _decode
    self.content_encoding, accept=self.accept)
  File "/usr/local/Desktop/celery/venv/local/lib/python2.7/site-packages/kombu/serialization.py", line 253, in loads
    raise self._for_untrusted_content(content_type, 'untrusted')
ContentDisallowed: Refusing to deserialize untrusted content of type pickle (application/x-python-serialize)

我目前没有在我的代码中调用/设置任何反序列化首选项。

当我自己运行该函数时,我得到的典型输出(如果它正在工作)看起来像:

QFont::setPixelSize: Pixel size <= 0 (0)
QFont::setPixelSize: Pixel size <= 0 (0)
QFont::setPixelSize: Pixel size <= 0 (0)
QFont::setPixelSize: Pixel size <= 0 (0)

我想知道这个输出是否是问题...我尝试隐藏屏幕截图命令的任何错误输出,但 cutycapt 仍然抛出相同的反序列化错误。中的其他函数tasks.py不会引发相同的错误。有任何想法吗?

4

1 回答 1

0

此错误是由于在 virtualenv 中打开 celery 任务文件,但在未正确安装 celery 的 virtualenv 之外 tasks.py运行 master引起的。call.py

于 2016-12-24T22:46:20.413 回答