python报错:UnicodeDecodeError: ‘ascii‘ codec can‘t decode byte 0xe0 in position 0: ordinal not in rang
生活随笔
收集整理的这篇文章主要介绍了
python报错:UnicodeDecodeError: ‘ascii‘ codec can‘t decode byte 0xe0 in position 0: ordinal not in rang
小编觉得挺不错的,现在分享给大家,帮大家做个参考.
在执行下面这段代码是,报错:UnicodeDecodeError: ‘ascii’ codec can’t decode byte 0xe0 in position 0: ordinal not in range(128)
(magic,img_type, img_size, algo, digest_len, sig_len)=struct.unpack("IIIIHH",img[0:20])if magic == 0x4f545348:img=img[20+16+4+sig_len+digest_len:]解决方法,如果是python2,则设置下sys.setdefaultencoding(‘gbk’)
if sys.version_info[0] < 3:tmp_encode=sys.getdefaultencoding()reload(sys)sys.setdefaultencoding('gbk')(magic,img_type, img_size, algo, digest_len, sig_len)=struct.unpack("IIIIHH",img[0:20])if magic == 0x4f545348:img=img[20+16+4+sig_len+digest_len:]if sys.version_info[0] < 3:sys.setdefaultencoding(tmp_encode) 《新程序员》:云原生和全面数字化实践50位技术专家共同创作,文字、视频、音频交互阅读总结
以上是生活随笔为你收集整理的python报错:UnicodeDecodeError: ‘ascii‘ codec can‘t decode byte 0xe0 in position 0: ordinal not in rang的全部内容,希望文章能够帮你解决所遇到的问题。
- 上一篇: travis-ci中的checkpatc
- 下一篇: python自动化测试locksetti