Skip to content

Commit

Permalink
formatter
Browse files Browse the repository at this point in the history
  • Loading branch information
MatthewZMSU committed Oct 31, 2024
1 parent 2832180 commit 27794a0
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions scrapypuppeteer/middlewares/restore.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,21 +95,26 @@ def process_response(self, request, response, spider):
# Update actions in context
self._update_context_actions(request, response)
elif (
puppeteer_request is not None
and response.status == HTTPStatus.UNPROCESSABLE_ENTITY
puppeteer_request is not None
and response.status == HTTPStatus.UNPROCESSABLE_ENTITY
):
# One PuppeteerRequest has failed with 422 error
if request_binding:
# Could not get context, retry
if request.meta.get("__request_binding_count", 0) < self.n_retry_restoring:
if (
request.meta.get("__request_binding_count", 0)
< self.n_retry_restoring
):
new_request = request.copy()
new_request.meta["__request_binding_count"] += 1
return new_request
else:
return self._restore_context(puppeteer_request, response)
return response

def _update_context_actions(self, request: ActionRequest, response: PuppeteerResponse):
def _update_context_actions(
self, request: ActionRequest, response: PuppeteerResponse
):
context_id = response.context_id
context_actions = self.context_actions[context_id]

Expand All @@ -130,7 +135,9 @@ def _restore_context(self, puppeteer_request: PuppeteerRequest, response):
if context_id in self.context_actions:
# Restoring
restoring_request = puppeteer_request.replace(
action=Compose(self.context_actions.pop(context_id), puppeteer_request.action),
action=Compose(
self.context_actions.pop(context_id), puppeteer_request.action
),
context_id=None,
page_id=None,
)
Expand Down

0 comments on commit 27794a0

Please sign in to comment.