当前位置:网站首页>出现UnicodeDecodeError: ‘ascii‘ codec can‘t decode byte 0xe9 in position 0: ordinal not in range解决方法
出现UnicodeDecodeError: ‘ascii‘ codec can‘t decode byte 0xe9 in position 0: ordinal not in range解决方法
2022-06-22 00:50:00 【码农研究僧】
1. 问题所示
在传输数据的时候
出现这个问题,如下所示:
File "./audioadmin/common.py", line 331, in send_alarm
.format(content, project_name, result))
UnicodeDecodeError: 'ascii' codec can't decode byte 0xe9 in position 0: ordinal not in range(128)
截图如下:
2. 问题分析
python2.7版本:(项目中使用的2版本):
python的编码转换会以unicode作为中间转码(unicode只有128的长度)
编码的过程都是先将其Ascii编码字符(默认编码方式)转换成unicode
通过上面的日志可得知无法转码,超出了范围,就报这种错误日志
本身编码的时候sys.defaultencoding默认是Ascii,而传入的编码是utf-8,格式不一样,自然就报错了
python3版本以上已经兼容了这种问题
测试python3 兼容的问题:
import sys
sys.getdefaultencoding() # 输出utf-8,而在python2.7中会输出Ascii
3. 解决方法
在项目中的开头引入:
import sys
defaultencoding = 'utf-8'
if sys.getdefaultencoding() != defaultencoding:
reload(sys)
sys.setdefaultencoding(defaultencoding)
边栏推荐
- [解决方案] 明厨亮灶视频边缘计算网关解决方案
- C语言动态内存函数的应用
- [ÑÖÏ Simulation Competition] fading (matrix acceleration, cyclic convolution, Gauss elimination)
- Yang Bing: oceanbase helps digital transformation, and native distributed database becomes the first choice for core system
- Install tensorflow and transformer on Orange Pie orangepi4b
- 【TensorRT】Video Swin-Transformer部署相关
- clean,compile,build,install,package区别
- Jpom 简介: 简而轻的低侵入式在线构建、自动部署、日常运维、项目监控软件
- Summary of new MySQL 8.0 features
- 4273. linked list consolidation
猜你喜欢

Brief introduction to jpom: simple and light low intrusive online construction, automatic deployment, daily operation and maintenance, and project monitoring software

今日内容

颜值、空间、安全、动力齐升级,新捷途X70S 8.79万元起售上市

Pytorch神经网络【手写数字识别】

LeetCode 5218. 个位数字为 K 的整数之和(枚举)

03 fastjson resolving circular references

ShardingSphere-proxy-5.0.0分布式哈希取模分片实现(四)

Cancellation meeting and automatic refund processing of message queue

刚学了一个炫酷3D三棱锥立体特效,快来看看
![[ÑÖÏ Simulation Competition] fading (matrix acceleration, cyclic convolution, Gauss elimination)](/img/4a/9dfcb699e36f67e14c036e3ae26417.png)
[ÑÖÏ Simulation Competition] fading (matrix acceleration, cyclic convolution, Gauss elimination)
随机推荐
IDEA 提示 Duplicated code fragment (15 lines long)
SparkRDD 案例:计算总成绩
修改字典的方法
03 FastJson 解决循环引用
Conversion between three file handles
Interview question catalog collection
Apache Doris实时数据分析保姆级使用教程
华为云发布桌面IDE-CodeArts
SQL操作:WITH表达式及其应用
SSO and oauth2 solutions
LeetCode 5218. 个位数字为 K 的整数之和(枚举)
内网学习笔记(9)
Cancellation meeting and automatic refund processing of message queue
Difference between integer and int
[Others] analysis of got and PLT in ELF
Standing at the digital tuyere, how can tooling enterprises "fly"
MySQL dump auto backup database shell script
Sending webhook of message queue to realize cross application asynchronous callback
4g/wifi energy consumption metering socket - monitoring voltage, current and power
動態規劃-01背包,分割等和子集,最後一塊石頭的重量