Python Scrapy TypeError errback_httpbin()缺少1个必需的位置参数:';失败';

Python Scrapy TypeError errback_httpbin()缺少1个必需的位置参数:';失败';,python,scrapy,request,web-crawler,Python,Scrapy,Request,Web Crawler,我正在尝试将我的错误函数分离到一个新的python文件中,这样我就可以在其他刮取程序中调用该文件。但它给出了这样一个错误: TypeError:errback\u httpbin()缺少1个必需的位置参数:“失败” 我需要调用的我的类通用内容: class Common_contents(scrapy.Spider): def errback_httpbin(self, failure): 我称之为上述类的主要类: def start_requests(self):

我正在尝试将我的错误函数分离到一个新的python文件中,这样我就可以在其他刮取程序中调用该文件。但它给出了这样一个错误:

TypeError:errback\u httpbin()缺少1个必需的位置参数:“失败”

我需要调用的我的类通用内容:

class Common_contents(scrapy.Spider):


     def errback_httpbin(self, failure):
我称之为上述类的主要类:

    def start_requests(self):
            
            yield scrapy.Request(self.start_urls[0], callback=self.parse,
            errback=Common_contents.errback_httpbin,dont_filter=True)
帮我解决这个问题


提前感谢

您应该像这样重写您的启动请求(使用self而不是类):


如果您需要为多个spider只编写一次errback\u httpbin,您可以使用。
在您的情况下,实现将如下所示:

class Common_contents:
....
     def errback_httpbin(self, failure):
     ## code

在这种情况下,
errback\u httpbin
from
Common\u contents
将可用于定义为
class SpiderName(scrapy.spider,Common\u contents)的每个spider类

class Common_contents:
....
     def errback_httpbin(self, failure):
     ## code
from *** import Common_contents
...
    class YourSpider(scrapy.Spider, Common_contents):
    ....
        def start_requests(self):
            yield scrapy.Request(self.start_urls[0], callback=self.parse,
                errback=self.errback_httpbin,dont_filter=True)