From 380fefd60611b84cd3fc4b7bef707cbee1d70198 Mon Sep 17 00:00:00 2001 From: Andrey Rakhmatullin Date: Tue, 19 Nov 2024 12:26:40 +0500 Subject: [PATCH] Set REQUEST_FINGERPRINTER_IMPLEMENTATION only on Scrapy < 2.12. --- tests/__init__.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/tests/__init__.py b/tests/__init__.py index ee54efb2..12e4b861 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -2,7 +2,9 @@ from os import environ from typing import Any, Dict, Optional +from packaging.version import Version from scrapy import Spider +from scrapy import __version__ as SCRAPY_VERSION from scrapy.crawler import Crawler from scrapy.utils.misc import load_object from scrapy.utils.test import get_crawler as _get_crawler @@ -25,13 +27,16 @@ "scrapy_zyte_api.ScrapyZyteAPISessionDownloaderMiddleware": 667, }, "REQUEST_FINGERPRINTER_CLASS": "scrapy_zyte_api.ScrapyZyteAPIRequestFingerprinter", - "REQUEST_FINGERPRINTER_IMPLEMENTATION": "2.7", # Silence deprecation warning "SPIDER_MIDDLEWARES": { "scrapy_zyte_api.ScrapyZyteAPISpiderMiddleware": 100, }, "ZYTE_API_KEY": _API_KEY, "TWISTED_REACTOR": "twisted.internet.asyncioreactor.AsyncioSelectorReactor", } +if Version(SCRAPY_VERSION) < Version("2.12"): + SETTINGS["REQUEST_FINGERPRINTER_IMPLEMENTATION"] = ( + "2.7" # Silence deprecation warning + ) try: import scrapy_poet # noqa: F401 except ImportError: