Skip to content

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

PY3 response bodies as bytes

nyov17b5e9fb86b3
diff --git a/tests/test_selector_csstranslator.py b/tests/test_selector_csstranslator.py
index 7ef9003aa..1bc8882f8 100644
--- a/tests/test_selector_csstranslator.py
+++ b/tests/test_selector_csstranslator.py
@@ -9,7 +9,7 @@ from cssselect.parser import SelectorSyntaxError
from cssselect.xpath import ExpressionError
-HTMLBODY = '''
+HTMLBODY = b'''
<html>
<body>
<div>
diff --git a/tests/test_selector_lxmldocument.py b/tests/test_selector_lxmldocument.py
index 7dab1d4b1..090cc21bc 100644
--- a/tests/test_selector_lxmldocument.py
+++ b/tests/test_selector_lxmldocument.py
@@ -6,7 +6,7 @@ from scrapy.http import TextResponse, HtmlResponse
class LxmlDocumentTest(unittest.TestCase):
def test_caching(self):
- r1 = HtmlResponse('http://www.example.com', body='<html><head></head><body></body></html>')
+ r1 = HtmlResponse('http://www.example.com', body=b'<html><head></head><body></body></html>')
r2 = r1.copy()
doc1 = LxmlDocument(r1)
@@ -19,7 +19,7 @@ class LxmlDocumentTest(unittest.TestCase):
def test_null_char(self):
# make sure bodies with null char ('\x00') don't raise a TypeError exception
- body = 'test problematic \x00 body'
+ body = b'test problematic \x00 body'
response = TextResponse('http://example.com/catalog/product/blabla-123',
headers={'Content-Type': 'text/plain; charset=utf-8'},
body=body)
diff --git a/tests/test_utils_iterators.py b/tests/test_utils_iterators.py
index a7042a6cf..f2780dcf1 100644
--- a/tests/test_utils_iterators.py
+++ b/tests/test_utils_iterators.py
@@ -13,7 +13,7 @@ class XmliterTestCase(unittest.TestCase):
xmliter = staticmethod(xmliter)
def test_xmliter(self):
- body = """<?xml version="1.0" encoding="UTF-8"?>\
+ body = b"""<?xml version="1.0" encoding="UTF-8"?>\
<products xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="someschmea.xsd">\
<product id="001">\
<type>Type 1</type>\
@@ -40,7 +40,7 @@ class XmliterTestCase(unittest.TestCase):
[[u'one'], [u'two']])
def test_xmliter_namespaces(self):
- body = """\
+ body = b"""\
<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:g="http://base.google.com/ns/1.0">
<channel>
@@ -83,7 +83,7 @@ class XmliterTestCase(unittest.TestCase):
self.assertRaises(StopIteration, next, iter)
def test_xmliter_encoding(self):
- body = '<?xml version="1.0" encoding="ISO-8859-9"?>\n<xml>\n <item>Some Turkish Characters \xd6\xc7\xde\xdd\xd0\xdc \xfc\xf0\xfd\xfe\xe7\xf6</item>\n</xml>\n\n'
+ body = b'<?xml version="1.0" encoding="ISO-8859-9"?>\n<xml>\n <item>Some Turkish Characters \xd6\xc7\xde\xdd\xd0\xdc \xfc\xf0\xfd\xfe\xe7\xf6</item>\n</xml>\n\n'
response = XmlResponse('http://www.example.com', body=body)
self.assertEqual(
self.xmliter(response, 'item').next().extract(),
@@ -95,7 +95,7 @@ class LxmlXmliterTestCase(XmliterTestCase):
xmliter = staticmethod(xmliter_lxml)
def test_xmliter_iterate_namespace(self):
- body = """\
+ body = b"""\
<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns="http://base.google.com/ns/1.0">
<channel>
@@ -124,7 +124,7 @@ class LxmlXmliterTestCase(XmliterTestCase):
self.assertEqual(node.xpath('text()').extract(), ['http://www.mydummycompany.com/images/item2.jpg'])
def test_xmliter_namespaces_prefix(self):
- body = """\
+ body = b"""\
<?xml version="1.0" encoding="UTF-8"?>
<root>
<h:table xmlns:h="http://www.w3.org/TR/html4/">
diff --git a/tests/test_utils_reqser.py b/tests/test_utils_reqser.py
index 40c44f7d9..a62f13e21 100644
--- a/tests/test_utils_reqser.py
+++ b/tests/test_utils_reqser.py
@@ -20,7 +20,7 @@ class RequestSerializationTest(unittest.TestCase):
callback='parse_item',
errback='handle_error',
method="POST",
- body="some body",
+ body=b"some body",
headers={'content-encoding': 'text/html; charset=latin-1'},
cookies={'currency': u'руб'},
encoding='latin-1',