on master help sign in
[fix] use raw response with etree.parsefromstring - Unicode strings with encoding declaration are not supported
commit8db527c1d233888b197bd2e8b2fbda8e88d0c60d authorAdam Tauber <asciimoo@gmail.com> dateMon 22 May 2017, 15:36 (9 years ago) parent259735f
2 files changed+7−7
searx/engines/bing_news.py+1−1 tests/unit/engines/test_bing_news.py+6−6
searx/engines/bing_news.py+1−1
@@ -85,7 +85,7 @@ def request(query, params):
8585def response(resp):
8686 results = []
8787
88− rss = etree.fromstring(resp.text)
88+ rss = etree.fromstring(resp.content)
8989
9090 ns = rss.nsmap
9191
tests/unit/engines/test_bing_news.py+6−6
@@ -36,10 +36,10 @@ class TestBingNewsEngine(SearxTestCase):
3636 self.assertRaises(AttributeError, bing_news.response, '')
3737 self.assertRaises(AttributeError, bing_news.response, '[]')
3838
39− response = mock.Mock(text='<html></html>')
39+ response = mock.Mock(content='<html></html>')
4040 self.assertEqual(bing_news.response(response), [])
4141
42− response = mock.Mock(text='<html></html>')
42+ response = mock.Mock(content='<html></html>')
4343 self.assertEqual(bing_news.response(response), [])
4444
4545 html = """<?xml version="1.0" encoding="utf-8" ?>
@@ -74,7 +74,7 @@ class TestBingNewsEngine(SearxTestCase):
7474 </item>
7575 </channel>
7676</rss>""" # noqa
77− response = mock.Mock(text=html.encode('utf-8'))
77+ response = mock.Mock(content=html.encode('utf-8'))
7878 results = bing_news.response(response)
7979 self.assertEqual(type(results), list)
8080 self.assertEqual(len(results), 2)
@@ -113,7 +113,7 @@ class TestBingNewsEngine(SearxTestCase):
113113 </item>
114114 </channel>
115115</rss>""" # noqa
116− response = mock.Mock(text=html.encode('utf-8'))
116+ response = mock.Mock(content=html.encode('utf-8'))
117117 results = bing_news.response(response)
118118 self.assertEqual(type(results), list)
119119 self.assertEqual(len(results), 1)
@@ -136,11 +136,11 @@ class TestBingNewsEngine(SearxTestCase):
136136 </channel>
137137</rss>""" # noqa
138138
139− response = mock.Mock(text=html.encode('utf-8'))
139+ response = mock.Mock(content=html.encode('utf-8'))
140140 results = bing_news.response(response)
141141 self.assertEqual(type(results), list)
142142 self.assertEqual(len(results), 0)
143143
144144 html = """<?xml version="1.0" encoding="utf-8" ?>gabarge"""
145− response = mock.Mock(text=html.encode('utf-8'))
145+ response = mock.Mock(content=html.encode('utf-8'))
146146 self.assertRaises(lxml.etree.XMLSyntaxError, bing_news.response, response)