diff --git a/Scrapy-Redis-Zhihu/scrapy_redis/utils.py b/Scrapy-Redis-Zhihu/scrapy_redis/utils.py new file mode 100644 index 0000000..b1a4681 --- /dev/null +++ b/Scrapy-Redis-Zhihu/scrapy_redis/utils.py @@ -0,0 +1,8 @@ +import six + + +def bytes_to_str(s, encoding='utf-8'): + """Returns a str if a bytes object is given.""" + if six.PY3 and isinstance(s, bytes): + return s.decode(encoding) + return s