瀏覽代碼

[fix] use raw response with etree.parsefromstring - Unicode strings with encoding declaration are not supported

Adam Tauber 7 年之前
父節點
當前提交
8db527c1d2
共有 2 個檔案被更改,包括 7 行新增7 行删除
  1. 1
    1
      searx/engines/bing_news.py
  2. 6
    6
      tests/unit/engines/test_bing_news.py

+ 1
- 1
searx/engines/bing_news.py 查看文件

@@ -85,7 +85,7 @@ def request(query, params):
85 85
 def response(resp):
86 86
     results = []
87 87
 
88
-    rss = etree.fromstring(resp.text)
88
+    rss = etree.fromstring(resp.content)
89 89
 
90 90
     ns = rss.nsmap
91 91
 

+ 6
- 6
tests/unit/engines/test_bing_news.py 查看文件

@@ -36,10 +36,10 @@ class TestBingNewsEngine(SearxTestCase):
36 36
         self.assertRaises(AttributeError, bing_news.response, '')
37 37
         self.assertRaises(AttributeError, bing_news.response, '[]')
38 38
 
39
-        response = mock.Mock(text='<html></html>')
39
+        response = mock.Mock(content='<html></html>')
40 40
         self.assertEqual(bing_news.response(response), [])
41 41
 
42
-        response = mock.Mock(text='<html></html>')
42
+        response = mock.Mock(content='<html></html>')
43 43
         self.assertEqual(bing_news.response(response), [])
44 44
 
45 45
         html = """<?xml version="1.0" encoding="utf-8" ?>
@@ -74,7 +74,7 @@ class TestBingNewsEngine(SearxTestCase):
74 74
         </item>
75 75
     </channel>
76 76
 </rss>"""  # noqa
77
-        response = mock.Mock(text=html.encode('utf-8'))
77
+        response = mock.Mock(content=html.encode('utf-8'))
78 78
         results = bing_news.response(response)
79 79
         self.assertEqual(type(results), list)
80 80
         self.assertEqual(len(results), 2)
@@ -113,7 +113,7 @@ class TestBingNewsEngine(SearxTestCase):
113 113
         </item>
114 114
     </channel>
115 115
 </rss>"""  # noqa
116
-        response = mock.Mock(text=html.encode('utf-8'))
116
+        response = mock.Mock(content=html.encode('utf-8'))
117 117
         results = bing_news.response(response)
118 118
         self.assertEqual(type(results), list)
119 119
         self.assertEqual(len(results), 1)
@@ -136,11 +136,11 @@ class TestBingNewsEngine(SearxTestCase):
136 136
     </channel>
137 137
 </rss>"""  # noqa
138 138
 
139
-        response = mock.Mock(text=html.encode('utf-8'))
139
+        response = mock.Mock(content=html.encode('utf-8'))
140 140
         results = bing_news.response(response)
141 141
         self.assertEqual(type(results), list)
142 142
         self.assertEqual(len(results), 0)
143 143
 
144 144
         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'))
146 146
         self.assertRaises(lxml.etree.XMLSyntaxError, bing_news.response, response)