最新消息:20210917 已从crifan.com换到crifan.org

【已解决】PySpider中执行self.crawl出错:NotImplementedError self.__call__() not implemented

出错 crifan 811浏览 0评论
折腾:
【已解决】PySpider模拟请求小花生api接口出错:requests.exceptions.HTTPError HTTP 500 Internal Server Error
期间,虽然已解决了:
【已解决】PySpider中self.crawl访问百度网页挂掉无响应
但是又出错:
[E 190329 10:43:58 base_handler:203] self.__call__() not implemented!
    Traceback (most recent call last):
      File "/Users/crifan/.local/share/virtualenvs/crawler_xiaohuasheng_app-zY4wnqo9/lib/python3.6/site-packages/pyspider/libs/base_handler.py", line 196, in run_task
        result = self._run_task(task, response)
      File "/Users/crifan/.local/share/virtualenvs/crawler_xiaohuasheng_app-zY4wnqo9/lib/python3.6/site-packages/pyspider/libs/base_handler.py", line 168, in _run_task
        raise NotImplementedError("self.%s() not implemented!" % callback)
    NotImplementedError: self.__call__() not implemented!
那去掉整个headers试试
问题依旧还是:
NotImplementedError: self.__call__() not implemented!
搜:
PySpider NotImplementedError: self.__call__() not implemented
not implemented · Issue #224 · binux/pyspider
难道是没加callback所以不执行?
通过换用:
http://www.xiaohuasheng.cn:83/Reading.svc/parentChildReadingBookQuery2
网页打开,get会返回:
{“M”:”9998″}
所以试试访问这个如何
        # for debug
        self.crawl(ParentChildReadingUrl,
            method="GET",
            callback=self.getParentChildReadingCallback,
            save=parentChildReadingParamDict
        )
是可以的:
-》说明url请求没问题。
-》说明正常加了callback,估计就可以了。
-》也再次注意到了,出错提示中有:
        raise NotImplementedError(“self.%s() not implemented!” % callback)
说的就是callback参数没有加
然后去试试
    def on_start(self):
        # for debug
        self.crawl("http://www.baidu.com", callback=self.getBaiduCallback)


    def getBaiduCallback(self, response):
        respUrl = response.url
        print("respUrl=%s" % respUrl)
        print("response=%s" % response)
即可正常返回内容:
respUrl=http://www.baidu.com/
response=<Response [200]>
【总结】
PySpider中的self.crawl中,如果没有加上callback参数,则会报错:
        raise NotImplementedError("self.%s() not implemented!" % callback)
    NotImplementedError: self.__call__() not implemented!
解决办法是:
必须加上callback参数
备注说明:
-》否则你获取某个页面,但是不处理返回内容,等价于无用操作
-》所以此处提示你必须要加上callback才行
-》只不过此处最终的报错信息:
    NotImplementedError: self.__call__() not implemented!
解释的不够清楚,而错误信息堆栈中的:
        raise NotImplementedError(“self.%s() not implemented!” % callback)
则解释清楚,是需要我们是实现callback参数才可以。

转载请注明:在路上 » 【已解决】PySpider中执行self.crawl出错:NotImplementedError self.__call__() not implemented

发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
90 queries in 0.173 seconds, using 23.39MB memory