pyspider mongodb onresult 报错

 9158Zsc 发布于 2022-10-25 01:20

如题,按照网上的例子写了个on_result,如下

 def on_result(self, result):
         con=MongoClient('mongodb://localhost:27017')
         resultdb=con.spider
         resultcollection=resultdb.resultdb
         if result:
           r={"project":"demo","result":result}
           resultcollection.insert_one(r)
           
           

但是有报错:

track.process  14.26ms 'Collection' object is not callable. If you meant to call the 'insert_one' method on a 'Collection' object it is failing because no such method exists.
[E 160112 13:20:03 base_handler:194] 'Collection' object is not callable. If you meant to call the 'insert_one' method on a 'Collection' object it is failing because no such method exists.
    Traceback (most recent call last):
      File "/usr/lib/python2.6/site-packages/pyspider-0.3.6-py2.6.egg/pyspider/libs/base_handler.py", line 192, in run_task
        self._run_func(self.on_result, result, response, task)
      File "/usr/lib/python2.6/site-packages/pyspider-0.3.6-py2.6.egg/pyspider/libs/base_handler.py", line 149, in _run_func
        return function(*arguments[:len(args) - 1])
      File "", line 47, in on_result
      File "/usr/lib64/python2.6/site-packages/pymongo/collection.py", line 1773, in __call__
        self.__name.split(".")[-1])
    TypeError: 'Collection' object is not callable. If you meant to call the 'insert_one' method on a 'Collection' object it is failing because no such method exists.

{
  "exception": "'Collection' object is not callable. If you meant to call the 'insert_one' method on a 'Collection' object it is failing because no such method exists.", 
  "follows": 0, 
  "logs": "[E 160112 13:20:03 base_handler:194] 'Collection' object is not callable. If you meant to call the 'insert_one' method on a 'Collection' object it is failing because no such method exists.\n    Traceback (most recent call last):\n      File \"/usr/lib/python2.6/site-packages/pyspider-0.3.6-py2.6.egg/pyspider/libs/base_handler.py\", line 192, in run_task\n        self._run_func(self.on_result, result, response, task)\n      File \"/usr/lib/python2.6/site-packages/pyspider-0.3.6-py2.6.egg/pyspider/libs/base_handler.py\", line 149, in _run_func\n        return function(*arguments[:len(args) - 1])\n      File \"\", line 47, in on_result\n      File \"/usr/lib64/python2.6/site-packages/pymongo/collection.py\", line 1773, in __call__\n        self.__name.split(\".\")[-1])\n    TypeError: 'Collection' object is not callable. If you meant to call the 'insert_one' method on a 'Collection' object it is failing because no such method exists.\n", 
  "ok": false, 
  "result": "{'category", 
  "time": 0.014256954193115234
}

请大侠帮我解答下,谢谢

撰写答案
今天,你开发时遇到什么问题呢?
立即提问
热门标签
PHP1.CN | 中国最专业的PHP中文社区 | PNG素材下载 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有