Pyhotn 中编码的问题:'ascii' codec can't decode byte 0xef in position 0: ordinal not in range(128)的错误
来源:互联网 发布:云豹直播app源码 编辑:程序博客网 时间:2024/06/06 12:24
python中包含中文字符串的编码不一致问题.
Python中字符串类型分为byte string 和 unicode string两种
问题就出在这边,unicode string 和 byte string 是不可以混合使用的,一旦混合使用了,就会产生这样的错误。例如:
self.response.out.write(“你好”+self.request.get(“argu”))
其中,”你好”被认为是byte string,而self.request.get(“argu”)的返回值被认为是unicode string。由于预设的解码器是ascii,所以就不能识别中文byte string。然后就报错了。
以下有两个解决方法:
1.将字符串全都转成byte string。
self.response.out.write(“你好”+self.request.get(“argu”).encode(“utf-8”))
2.将字符串全都转成unicode string。
self.response.out.write(u”你好”+self.request.get(“argu”))
byte string转换成unicode string可以这样转unicode(unicodestring, “utf-8”)
[参考](http://blog.csdn.net/use_my_heart/article/details/51303317)
阅读全文
0 0
- Pyhotn 中编码的问题:'ascii' codec can't decode byte 0xef in position 0: ordinal not in range(128)的错误
- Pyhotn 中编码的问题:'ascii' codec can't decode byte 0xef in position 0: ordinal not in range(128)的错误
- Pyhotn 中编码的问题:'ascii' codec can't decode byte 0xef in position 0: ordinal not in range(128)的错误
- 'ascii' codec can't decode byte 0xef in position 0: ordinal not in range(128)
- ascii' codec can't decode byte 0xef in position 0: ordinal not in range(128)
- UnicodeDecodeError: 'ascii' codec can't decode byte 0xef in position 10: ordinal not in range(128)
- UnicodeDecodeError: 'ascii' codec can't decode byte 0xef in position 458: ordinal not in range(128)
- 'ascii' codec can't decode byte 0xe7 in position 12: ordinal not in range(128)的错误
- 'ascii' codec can't decode byte 0xef in position 0:ordinal not in range(128)错误解决与原理分析
- 'ascii' codec can't decode byte 0xe4 in position 0: ordinal not in range(128)
- ascii codec can't decode byte 0xe8 in position 0:ordinal not in range(128)
- ascii codec can't decode byte 0xe8 in position 0:ordinal not in range(128)
- 'ascii' codec can't decode byte 0xe4 in position 0: ordinal not in range(128)
- 'ascii' codec can't decode byte 0xc4 in position 27: ordinal not in range(128)
- 'ascii' codec can't decode byte 0x** in position **, ordinal not in range(128)
- 【Python错误】 'ascii' codec can't decode byte 0xe7 in position 0: ordinal not in range(128)
- UnicodeDecodeError: 'ascii' codec can't decode byte 0xe7 in position 0: ordinal not in range(128)错误解
- python 处理中文时出现的错误'ascii' codec can't decode byte 0xe9 in position 0: ordinal not in range(128)" 解决方法
- shiro实现不同身份使用不同Realm进行验证
- Spring(四)装配
- Windows环境下配置php的curl扩展
- redis源码安装出现fatal error: jemalloc/jemalloc.h: No such file or directory
- ALSA声卡驱动中的DAPM详解之五:建立widget之间的连接关系
- Pyhotn 中编码的问题:'ascii' codec can't decode byte 0xef in position 0: ordinal not in range(128)的错误
- JavaScript原型对象
- 6.AsyncTask中的FutureTask和Callable
- 解决微信支付 errCode返回-1
- emmc和ssd的区别
- 【学习opencv】opencv人脸检测
- 微信小程序入门——页面跳转、数据传递、数据接收
- oj网站的训练题:输入两个数A,B,输出A+B的值
- Hibernate入门七(关联对象)