Update scrapy/downloadermiddlewares/httpcompression.py

Co-authored-by: Adrián Chaves <adrian@chaves.io>
This commit is contained in:
Georgiy Zatserklianyi 2020-10-30 21:23:29 +02:00 committed by GitHub
parent 872b2e4ce4
commit e9c3188189
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 6 additions and 1 deletions

View File

@ -25,7 +25,12 @@ class HttpCompressionMiddleware:
def from_crawler(cls, crawler):
if not crawler.settings.getbool('COMPRESSION_ENABLED'):
raise NotConfigured
return cls(crawler.stats)
try:
return cls(stats=crawler.stats)
except TypeError:
result = cls()
result.stats = crawler.stats
return result
def process_request(self, request, spider):
request.headers.setdefault('Accept-Encoding',