In scrapy I'm trying to write a downloader middleware which filters the responses with 401, 403,410 and sends these URLs some new requests. The error says that response_request must return a Response or a Request. Because I yield 10 requests to make sure if the failed urls are tried enough times. How should I fix it? Thank you.
Here is my middleware code which I activated on settings.py
'''
class NegativeResponsesDownloaderMiddlerware(Spider):
def process_response(self, request, response, spider): ## encode each request with its http status
# Called with the response returned from the downloader.
print("---(NegativeResponsesDownloaderMiddlerware)")
filtered_status_list = ['401', '403', '410']
adaptoz = FailedRequestsItem()
if response.status in filtered_status_list:
adaptoz['error_code'][response.url] = response.status
print("---(process_response) => Sending URL back do DOWNLOADER: URL =>",response.url)
for i in range(self.settings.get('ERROR_HANDLING_ATTACK_RATE')):
yield Request(response.url, self.check_retrial_result,headers = self.headers)
raise IgnoreRequest(f"URL taken out from first flow. Error Code: ", adaptoz['error_code']," => URL = ", resp)
else:
return response
# Must either;
# - return a Response object
# - return a Request object
# - or raise IgnoreRequest
def check_retrial_result(self, response):
if response.status == 200:
x = XxxSpider()
x.parse_event(response)
else:
return None
'''