requests爬虫请求报错:UnicodeEncodeError: 'latin-1' codec can't encode character '\u2026' in position 30

浏览器在显示User-Agent属性时,应为属性值过长,所以使用了省略号,导致添加过程中造成了编译错误。

错误代码:

	headers = {
	    'User-Agent':r'Mozilla/5.0 (Windows NT 10.0; …) Gecko/20100101 Firefox/60.0',
	    'Referer': Referer,
	    'Connection': 'keep-alive',
	    'Host':'m.emoney.cn'
	    }

主要原因就是复制User-Agent时,因为它太长了,没有等它扩展开来,就直接复制,部分内容变成了省略号

正确的长这样子

Mozilla/5.0 (Windows NT 10.0; WOW64; rv:60.0)Gecko/20100101 Firefox/60.0'

关键错误信息如下:

  File "/usr/lib/python3.5/http/client.py", line 1106, in request
    self._send_request(method, url, body, headers)
  File "/usr/lib/python3.5/http/client.py", line 1146, in _send_request
    self.putheader(hdr, value)
  File "/usr/lib/python3.5/http/client.py", line 1078, in putheader
    values[i] = one_value.encode('latin-1')
UnicodeEncodeError: 'latin-1' codec can't encode character '\u2026' in position 30: ordinal not in range(256)

 

你可能感兴趣的:(pyhthon安装以及错误处理)