Skip to content

Commit

Permalink
fix: Read data from file in ValidateJSONMiddleware
Browse files Browse the repository at this point in the history
  • Loading branch information
jpmckinney committed Apr 11, 2024
1 parent 79ec960 commit d6e8a7f
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion kingfisher_scrapy/spidermiddlewares.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,12 @@ async def process_spider_output(self, response, result, spider):
yield item
continue

data = item.data
if hasattr(data, 'read'):
data = data.read()

try:
json.loads(item.data)
json.loads(data)
yield item
except json.JSONDecodeError:
spider.crawler.stats.inc_value('invalid_json_count')
Expand Down

0 comments on commit d6e8a7f

Please sign in to comment.