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