![](/img/trans.png)
[英]UnicodeDecodeError: 'charmap' codec can't decode byte 0x9d in position X: character maps to <undefined>
[英]UnicodeDecodeError: 'charmap' codec can't decode byte 0x9d in position 1010494: character maps to <undefined>
請為此我需要幫助:
url ='https://www.sec.gov/Archives/edgar/data/1437750/0001477932-13-004416.txt'
with open('file', 'wb') as f:
f.write(requests.get('%s' % url).content)
with open('file', 'r') as t:
words= t.read()
上面給了我以下錯誤:
return codecs.charmap_decode(input,self.errors,decoding_table)[0]
UnicodeDecodeError: 'charmap' codec can't decode byte 0x9d in position 1010494: character maps to < undefined>
謝謝!
我只是遇到了同樣的問題。 當我嘗試讀取文件時,我的一個字符串有一個雙倍空格:“”。 刪除該雙精度空格可解決0x9d問題。
為什么要以二進制形式寫入文件,然后以unicode字符串讀取文件? 直到您告訴它使用哪種編解碼器,Python才知道如何從原始流中解碼一些字節。 由於您在第一個命令中流式傳輸的文件未經過utf-8編碼,因此在讀取文件時,請嘗試將其解碼為latin-1
:
with open('file', 'r', encoding='latin-1') as t:
words = t.read()
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.