当前位置:主页 > 软件编程 > Python代码 >

解决python3 网络请求路径包含中文的问题

时间:2021-04-01 08:17:21 | 栏目:Python代码 | 点击:

在爬一个网站的时候,端点包含中文浏览器是可以自动解决这个转换的,在代码中就需要处理一下了。

请求过程的异常如下:

self._output(request.encode('ascii'))
UnicodeEncodeError: 'ascii' codec can't encode characters in position 10-11: ordinal not in range(128)

解决如下:

import urllib.parse
reqStr = '你好'
encodeStr = urllib.parse.quote(reqStr)
print(encodeStr)

您可能感兴趣的文章:

相关文章