我正在创建此请求:
url="http://tn.ai/1244844"
response = self.http.request('GET', urllib.parse.quote(url, safe=':/?='), headers={"User-Agent": "Mozilla/5.0"})
我在这里收到所有标题:
response.getheaders()
结果是:
Content-Type: text/html; charset=UTF-8
Location: =?utf-8?b?aHR0cHM6Ly93d3cudGFzbmltbmV3cy5jb20vZmEvbmV3cy8xMzk1LzA4LzMwLzEyNDQ4NDQvw5nChsOawq/DmMKnw5nChy3DmMKow5jCrsOYwrTDm8KMLcOZ?=
بارزÙ-با-ÙاÚاÙ-را-Ù
Ø´Ú©Ù-کردÙ-است
Server: Microsoft-IIS/8.5
Date: Sun, 20 Nov 2016 21:28:25 GMT
Content-Length: 253
现在,由于我在Location
值中有一些未知值,我在解析标题值时遇到此错误:
Failed to parse headers (url=http://www.tasnimnews.com:80/fa/news/1395/08/30/1244844/%D9%86%DA%AF%D8%A7%D9%87-%D8%A8%D8%AE%D8%B4%DB%8C-%D9%85%D8%A8%D8%A7%D8%B1%D8%B2%D9%87-%D8%A8%D8%A7-%D9%82%D8%A7%DA%86%D8%A7%D9%82-%D8%B1%D8%A7-%D9%85%D8%B4%DA%A9%D9%84-%DA%A9%D8%B1%D8%AF%D9%87-%D8%A7%D8%B3%D8%AA): [MissingHeaderBodySeparatorDefect()], unparsed data: 'بارزÙ\x87-با-Ù\x82اÚ\x86اÙ\x82-را-Ù\x85Ø´Ú©Ù\x84-کردÙ\x87-است\r\nServer: Microsoft-IIS/8.5\r\nDate: Sun, 20 Nov 2016 21:28:25 GMT\r\nContent-Length: 253\r\n\r\n'
Traceback (most recent call last):
File "C:\Python34\lib\site-packages\urllib3\connectionpool.py", line 405, in _make_request
assert_header_parsing(httplib_response.msg)
File "C:\Python34\lib\site-packages\urllib3\util\response.py", line 59, in assert_header_parsing
raise HeaderParsingError(defects=defects, unparsed_data=unparsed_data)
urllib3.exceptions.HeaderParsingError: [MissingHeaderBodySeparatorDefect()], unparsed data: 'بارزÙ\x87-با-Ù\x82اÚ\x86اÙ\x82-را-Ù\x85Ø´Ú©Ù\x84-کردÙ\x87-است\r\nServer: Microsoft-IIS/8.5\r\nDate: Sun, 20 Nov 2016 21:28:25 GMT\r\nContent-Length: 253\r\n\r\n'
解决方案是什么?
如何防止出现此错误?
我应该手动编辑位置值吗?
如果是,怎么样?