-1

I want to retry Scrapy request when if it gets an exception and the response status code is 429. The problem is I don't know how to get the response status on the process_exception. How can I do it since it seems there is no way to access response object inside process_exception?

class FakeUserAgentErrorRetryMiddleware(RetryMiddleware):

    def process_exception(self, request, exception, spider):
        if type(exception) == FakeUserAgentError: return self._retry(request, exception, spider)
Aminah Nuraini
  • 18,120
  • 8
  • 90
  • 108

1 Answers1

0

If you want to retry a request when you have response.status = 429 you should add 429 in RETRY_HTTP_CODES

RETRY_HTTP_CODES = [429]

You can set also set the maximum number of times to retry with RETRY_TIMES

parik
  • 2,313
  • 12
  • 39
  • 67