diff --git a/sh_scrapy/extension.py b/sh_scrapy/extension.py index 6512ce3..00dc758 100644 --- a/sh_scrapy/extension.py +++ b/sh_scrapy/extension.py @@ -4,6 +4,7 @@ import scrapy from scrapy import signals +from scrapy import version_info as SCRAPY_VERSION_INFO from scrapy.exceptions import ScrapyDeprecationWarning from scrapy.exporters import PythonItemExporter from scrapy.http import Request @@ -41,7 +42,10 @@ def __init__(self, crawler): self.crawler = crawler self.logger = logging.getLogger(__name__) self._write_item = self.pipe_writer.write_item - self.exporter = PythonItemExporter() + kwargs = {} + if SCRAPY_VERSION_INFO < (2, 11): + kwargs["binary"] = False + self.exporter = PythonItemExporter(**kwargs) @classmethod def from_crawler(cls, crawler): diff --git a/tests/test_extension.py b/tests/test_extension.py index 5a19bee..067e3cc 100644 --- a/tests/test_extension.py +++ b/tests/test_extension.py @@ -26,6 +26,7 @@ def test_hs_ext_init(hs_ext): assert hs_ext.crawler assert hs_ext._write_item == hs_ext.pipe_writer.write_item assert isinstance(hs_ext.exporter, PythonItemExporter) + assert hs_ext.exporter.export_item({"a": "b"}) == {"a": "b"} @pytest.mark.skipif(sys.version_info < (3, 7), reason="requires python3.7")