Skip to content

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

PY3 fix tests pipelines images

nyov34eced0ee822
diff --git a/scrapy/pipelines/images.py b/scrapy/pipelines/images.py
index 8b3bc2222..ff73b44b7 100644
--- a/scrapy/pipelines/images.py
+++ b/scrapy/pipelines/images.py
@@ -15,6 +15,7 @@ except ImportError:
from PIL import Image
from scrapy.utils.misc import md5sum
+from scrapy.utils.python import to_bytes
from scrapy.http import Request
from scrapy.exceptions import DropItem
#TODO: from scrapy.pipelines.media import MediaPipeline
@@ -138,7 +139,7 @@ class ImagesPipeline(FilesPipeline):
return self.image_key(url)
## end of deprecation warning block
- image_guid = hashlib.sha1(url).hexdigest() # change to request.url after deprecation
+ image_guid = hashlib.sha1(to_bytes(url)).hexdigest() # change to request.url after deprecation
return 'full/%s.jpg' % (image_guid)
def thumb_path(self, request, thumb_id, response=None, info=None):
@@ -163,7 +164,7 @@ class ImagesPipeline(FilesPipeline):
return self.thumb_key(url, thumb_id)
## end of deprecation warning block
- thumb_guid = hashlib.sha1(url).hexdigest() # change to request.url after deprecation
+ thumb_guid = hashlib.sha1(to_bytes(url)).hexdigest() # change to request.url after deprecation
return 'thumbs/%s/%s.jpg' % (thumb_id, thumb_guid)
# deprecated
diff --git a/tests/test_pipeline_images.py b/tests/test_pipeline_images.py
index 04cec4b8e..f52fb4d3d 100644
--- a/tests/test_pipeline_images.py
+++ b/tests/test_pipeline_images.py
@@ -10,6 +10,7 @@ from scrapy.item import Item, Field
from scrapy.http import Request, Response
from scrapy.settings import Settings
from scrapy.pipelines.images import ImagesPipeline
+from scrapy.utils.python import to_bytes
skip = False
try:
@@ -100,11 +101,11 @@ class DeprecatedImagesPipeline(ImagesPipeline):
return self.image_key(url)
def image_key(self, url):
- image_guid = hashlib.sha1(url).hexdigest()
+ image_guid = hashlib.sha1(to_bytes(url)).hexdigest()
return 'empty/%s.jpg' % (image_guid)
def thumb_key(self, url, thumb_id):
- thumb_guid = hashlib.sha1(url).hexdigest()
+ thumb_guid = hashlib.sha1(to_bytes(url)).hexdigest()
return 'thumbsup/%s/%s.jpg' % (thumb_id, thumb_guid)