Python发送Http请求时,中文乱码问题的解决方法
2017-10-05 23:27
901 查看
解决方法:
先encode再quote。
原理:
msg.encode('utf-8')是解决中文乱码问题。
quote():假如URL的 name 或者 value 值中有『&』、『%』或者『=』等符号,就会有问题。所以URL中的参数字符串也需要把『&=』等符号进行编码,quote()就是对参数字符串中的『&=%』等符号进行编码。
例子:
先encode再quote。
原理:
msg.encode('utf-8')是解决中文乱码问题。
quote():假如URL的 name 或者 value 值中有『&』、『%』或者『=』等符号,就会有问题。所以URL中的参数字符串也需要把『&=』等符号进行编码,quote()就是对参数字符串中的『&=%』等符号进行编码。
例子:
# -*- coding: UTF-8 -*- # python2.7 from urllib import quote import requests def httpGet(sUrl): header = {} try: response=requests.get(sUrl, headers=header) sText = response.text return sText except BaseException: print BaseException def demo(msg): sEncodeMsg = quote(msg.encode('utf-8')) url = 'http://www.youdao.com/w/eng/' + sEncodeMsg print httpGet (url) demo(u'90%的数据')
相关文章推荐
- python csv 格式文件 中文乱码问题解决方法
- python 采集中文乱码问题的完美解决方法
- Python BeautifulSoup中文乱码问题的2种解决方法
- Python实现的json文件读取及中文乱码显示问题解决方法
- Python BeautifulSoup中文乱码问题的2种解决方法
- python 采集中文乱码问题的完美解决方法
- PHP基于curl post实现发送url及相关中文乱码问题解决方法
- Python2.x中文乱码问题解决方法
- 使用http请求,中文乱码问题--解决方法
- Python Email应用的中文乱码问题解决方法
- 【转】python csv 格式文件 中文乱码问题解决方法
- Python BeautifulSoup中文乱码问题的2种解决方法
- Python2.x中文乱码问题解决方法
- Python BeautifulSoup中文乱码问题的2种解决方法
- python读取\t\n的文件转换成html表格发送邮件(解决中文乱码问题)
- ajax+php POST方法发送数据(解决后端中文乱码问题)
- Python2.x中文乱码问题解决方法
- python邮件发送(带附件,解决中文乱码问题)
- httpClient使用postMethod方法发送请求,携带参数并解决中文乱码问题
- 使用http请求,中文乱码问题--解决方法