celery的task返回response对象报错
celery配置为:
app.config.update(
CELERY_BROKER_URL='amqp://guest:guest@localhost:5672//',
CELERY_RESULT_BACKEND='redis://localhost:6379/0'
)
celery = make_celery(app)
celery.conf.update(
CELERY_TASK_SERIALIZER='pickle',
CELERY_RESULT_SERIALIZER = 'pickle',
RYD_POOL = 'gevent')
有些奇怪是因为,celery和flask结合在一起,代码和问题无关就不贴了。
用celery做一个爬取的任务。代码如下
@celery.task()
def fetcher(url):
return requests.get('http://'+url)
请求报错:
[2016-11-14 14:58:23,075: ERROR/MainProcess]
Task celerytask.fetcher[dfc93f01-cdeb-40fb-a42a-cbf9c9cbf6e1]
raised unexpected: TypeError("object of type 'Response' has no len()",)Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/celery/app/trace.py", line 425, in trace_taskparent_id=uuid, root_id=root_id,File "/usr/local/lib/python2.7/dist-packages/celery/canvas.py", line 221, in apply_asyncreturn _apply(args, kwargs, **options)
File "/usr/local/lib/python2.7/dist-packages/celery/app/task.py", line 536, in apply_async**optionsFile "/usr/local/lib/python2.7/dist-packages/celery/app/base.py", line 709, in send_taskroot_id, parent_id, shadow, chain,
File "/usr/local/lib/python2.7/dist-packages/celery/app/amqp.py", line 333, in as_task_v2argsrepr = saferepr(args, self.argsrepr_maxsize)
File "/usr/local/lib/python2.7/dist-packages/celery/utils/saferepr.py", line 74, in saferepro, maxlen=maxlen, maxlevels=maxlevels, seen=seenFile "/usr/local/lib/python2.7/dist-packages/celery/utils/saferepr.py", line 104, in _safereprfor token, it in reprstream(stack, seen=seen, maxlevels=maxlevels):
File "/usr/local/lib/python2.7/dist-packages/celery/utils/saferepr.py", line 155, in reprstreamfor val in it:
File "/usr/local/lib/python2.7/dist-packages/celery/utils/saferepr.py", line 91, in _chainlistsize = len(it)
TypeError: object of type 'Response' has no len()
该怎么解决呢?
调用为:
fetcher.delay(url)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论