Python发送Http请求时,中文乱码问题的解决方法
来源:互联网 发布:乐视无线显示网络异常 编辑:程序博客网 时间:2024/05/22 15:56
解决方法:
先encode再quote。
原理:
msg.encode('utf-8')是解决中文乱码问题。
quote():假如URL的 name 或者 value 值中有『&』、『%』或者『=』等符号,就会有问题。所以URL中的参数字符串也需要把『&=』等符号进行编码,quote()就是对参数字符串中的『&=%』等符号进行编码。
例子:
# -*- coding: UTF-8 -*-# python2.7from urllib import quoteimport requestsdef 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%的数据')
阅读全文
0 0
- Python发送Http请求时,中文乱码问题的解决方法
- 使用http请求,中文乱码问题--解决方法
- 使用http请求,中文乱码问题--解决方法
- Android向服务器发送请求时的中文乱码问题
- Http请求post方法,请求和响应中文乱码问题的一点解决方法
- 客户端发送的post请求,request中的中文乱码问题
- Ajax中向Servlet发送请求时中文乱码问题
- SpringMvc发送post请求中文乱码问题
- jsp带中文请求参数的乱码问题的解决方法
- get请求中的中文乱码问题的解决方法
- 关于Android的HTTP请求中文乱码问题(备忘)
- Android学习笔记:Android向服务器发送请求时的中文乱码问题
- 有道翻译发送带中文的get请求时乱码问题
- Android学习笔记:Android向服务器发送请求时的中文乱码问题
- Get请求中文乱码问题有效解决方法
- http 请求服务器收到中文乱码问题
- Http get请求 中文乱码问题
- 【已解决】http请求中文乱码问题
- Ctex中插入Visio图的步骤
- 洛谷P2878 保护花朵
- atoi函数的C实现
- SpringMVC原理及配置详解
- HDU 1325 Is It A Tree?
- Python发送Http请求时,中文乱码问题的解决方法
- UVa 113|Power of Cryptography|牛顿迭代法|pow函数的应用
- 20171005memo
- 1024. 科学计数法 (20)
- 网络编程_高级函数
- JS动画函数的封装
- Bzoj 1647: Fliptile 翻格子游戏 状态压缩
- 捕捉Win32窗口操作
- 【专题】区间dp