code: def handle_unexpected_redirect_to_login_page(self, response):
          
          next_url = URLObject(response.url).query_dict.get("next")
          login_url = (
              URLObject("http://")
              .with_hostname(self.domain)
              .with_port(self.port)
              .with_path(LOGIN_API_PATH)
          )
          if next_url:
              login_url = login_url.set_query_param("next", next_url)
  
          credentials = {
              "email": self.login_email,
              "password": self.login_password,
          }
          headers = {
              b"X-CSRFToken": get_csrf_token(response),
          }
          yield scrapy.FormRequest(
              login_url,
              formdata=credentials,
              headers=headers,
              callback=self.after_login,
              errback=self.handle_error
          )
docs: This method is called if the crawler has been unexpectedly logged out.
          If that happens, and the crawler requests a page that requires a
          logged-in user, the crawler will be redirected to a login page,
          with the originally-requested URL as the `next` query parameter.
  
          This method simply causes the crawler to log back in using the saved
          email and password credentials. We rely on the fact that the login
          page will redirect the user to the URL in the `next` query parameter
          if the login is successful -- this will allow the crawl to resume
          where it left off.
  
          This is method is very much like the `get_initial_login()` method,
          but the callback is `self.after_login` instead of
          `self.after_initial_login`.