Skip to content

Scrapy, a fast high-level web crawling & scraping framework for Python.

Switch to pickle protocol 4

Eugenio Lacuestad0bb04f08936
diff --git a/scrapy/exporters.py b/scrapy/exporters.py
index 0cb6cef98..349a9586b 100644
--- a/scrapy/exporters.py
+++ b/scrapy/exporters.py
@@ -250,7 +250,7 @@ class CsvItemExporter(BaseItemExporter):
class PickleItemExporter(BaseItemExporter):
- def __init__(self, file, protocol=2, **kwargs):
+ def __init__(self, file, protocol=4, **kwargs):
super().__init__(**kwargs)
self.file = file
self.protocol = protocol
diff --git a/scrapy/extensions/httpcache.py b/scrapy/extensions/httpcache.py
index 8546628a8..7972b58b1 100644
--- a/scrapy/extensions/httpcache.py
+++ b/scrapy/extensions/httpcache.py
@@ -250,7 +250,7 @@ class DbmCacheStorage:
'headers': dict(response.headers),
'body': response.body,
}
- self.db['%s_data' % key] = pickle.dumps(data, protocol=2)
+ self.db['%s_data' % key] = pickle.dumps(data, protocol=4)
self.db['%s_time' % key] = str(time())
def _read_data(self, spider, request):
@@ -317,7 +317,7 @@ class FilesystemCacheStorage:
with self._open(os.path.join(rpath, 'meta'), 'wb') as f:
f.write(to_bytes(repr(metadata)))
with self._open(os.path.join(rpath, 'pickled_meta'), 'wb') as f:
- pickle.dump(metadata, f, protocol=2)
+ pickle.dump(metadata, f, protocol=4)
with self._open(os.path.join(rpath, 'response_headers'), 'wb') as f:
f.write(headers_dict_to_raw(response.headers))
with self._open(os.path.join(rpath, 'response_body'), 'wb') as f:
diff --git a/scrapy/extensions/spiderstate.py b/scrapy/extensions/spiderstate.py
index 2e5ff569f..bea00596e 100644
--- a/scrapy/extensions/spiderstate.py
+++ b/scrapy/extensions/spiderstate.py
@@ -26,7 +26,7 @@ class SpiderState:
def spider_closed(self, spider):
if self.jobdir:
with open(self.statefn, 'wb') as f:
- pickle.dump(spider.state, f, protocol=2)
+ pickle.dump(spider.state, f, protocol=4)
def spider_opened(self, spider):
if self.jobdir and os.path.exists(self.statefn):
diff --git a/scrapy/squeues.py b/scrapy/squeues.py
index d0686dac3..8d05bd0d0 100644
--- a/scrapy/squeues.py
+++ b/scrapy/squeues.py
@@ -81,7 +81,7 @@ def _scrapy_non_serialization_queue(queue_class):
def _pickle_serialize(obj):
try:
- return pickle.dumps(obj, protocol=2)
+ return pickle.dumps(obj, protocol=4)
# Python <= 3.4 raises pickle.PicklingError here while
# 3.5 <= Python < 3.6 raises AttributeError and
# Python >= 3.6 raises TypeError