pyspider mongodb onresult 报错

发布于 2022-09-02 00:22:53 字数 2759 浏览 6 评论 0

如题,按照网上的例子写了个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 "<dem>", 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 \"<dem>\", 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
}

请大侠帮我解答下,谢谢

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文