pyspider mongodb onresult 报错
阿神
阿神 2017-04-28 09:06:30
0
0
829

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

请大侠帮我解答下,谢谢

阿神
阿神

闭关修行中......

Antworte allen(0)
Beliebte Tutorials
Mehr>
Neueste Downloads
Mehr>
Web-Effekte
Quellcode der Website
Website-Materialien
Frontend-Vorlage