From 89d4bf2f332871a4cc2b288b8408542861426625 Mon Sep 17 00:00:00 2001 From: Max Varlamov <47754003+mxsnq@users.noreply.github.com> Date: Mon, 11 Sep 2023 14:53:03 +0300 Subject: [PATCH] fix: context id may be missing on error responses (#21) --- scrapypuppeteer/middleware.py | 4 +++- setup.py | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/scrapypuppeteer/middleware.py b/scrapypuppeteer/middleware.py index f6c5852..4063e98 100644 --- a/scrapypuppeteer/middleware.py +++ b/scrapypuppeteer/middleware.py @@ -156,7 +156,9 @@ def process_response(self, request, response, spider): response_cls = self._get_response_class(puppeteer_request.action) if response.status != 200: - self.used_contexts[id(spider)].add(response_data['contextId']) + context_id = response_data.get('contextId') + if context_id: + self.used_contexts[id(spider)].add(context_id) return response return self._form_response(response_cls, response_data, diff --git a/setup.py b/setup.py index 185ef43..1b8503f 100644 --- a/setup.py +++ b/setup.py @@ -7,7 +7,7 @@ setup( name='scrapy-puppeteer-client', - version='0.1.3', + version='0.1.4', description='A library to use Puppeteer-managed browser in Scrapy spiders', long_description=long_description, long_description_content_type="text/markdown",