Python讀取檔案時出現UnicodeDecodeError: 'gbk' codec can't decode byte 0x80 in position xx: 解決方案
Python在讀取檔案時
with open('article.txt') as f: # 開啟新的文字
text_new = f.read() # 讀取文字資料
出現錯誤:
UnicodeDecodeError: 'gbk' codec can't decode byte 0x80 in position 145: illegal multibyte sequence
此時有兩種解決方案:
1.將第一條語法改為
with open('article.txt','rb') as f: # 開啟新的文字
text_new = f.read() # 讀取文字資料
2.將第一條語法改為
with open('article.txt','r',encoding='UTF-8') as f: # 開啟新的文字
text_new = f.read() # 讀取文字資料
---------------------
作者:zhang__shuang_
來源:CSDN
原文:https://blog.csdn.net/zhang__shuang_/article/details/82527314
版權宣告:本文為博主原創文章,轉載請附上博文連結!
相關文章
- Python報錯:UnicodeDecodeError: 'gbk' codec can't decode byte ...PythonUnicodeError
- Python3.7使用pip install xxxx報錯:UnicodeDecodeError: 'gbk' codec can't decode bytePythonUnicodeError
- tensorflow讀取圖片時出現錯誤UnicodeDecodeError: 'utf-8' codec can't decode byte 0xff in position 0: invalid sUnicodeError
- UnicodeDecodeError: 'utf-8' codec can't decode byte 0xc8 in position 0: invalid continuation byteUnicodeError
- pipenv install error UnicodeDecodeError: 'utf8' codec can't decode byte 0xb4 in positionErrorUnicode
- Python讀取csv檔案出現解碼錯誤UnicodeDecodeError: ‘utf-8‘ codec can‘t decodPythonUnicodeError
- pip install ... ERROR: UnicodeDecodeError: ‘gbk‘ codec can‘t decode/ python setup.py egg_info CheckErrorUnicodePython
- PyMySQL 獲取資料 'utf-8' codec can't decode byte 0xed in position 2: 錯誤MySql
- python在用pandas對csv檔案處理的時候報UnicodeDecodeError: ‘utf-8‘ codec can‘t decode byte 0xb6。。。的錯誤PythonUnicodeError
- Python——UnicodeEncodeError: 'ascii' codec can't encode/decode charactersPythonUnicodeErrorASCII
- Python3解決UnicodeEncodeError: 'ascii' codec can't encode characters in position 0PythonUnicodeErrorASCII
- PIP3安裝報錯nicodeDecodeError: 'ascii' codec can't decode byte 0xc3ErrorASCII
- day1 UnicodeEncodeError: 'gbk' codec can't encode character '\xa0' in position 2490: illegal multi...UnicodeError
- 【python爬蟲】用selenium爬時報錯UnicodeEncodeError: ‘gbk‘ codec can‘t encode character ‘\u2022‘Python爬蟲UnicodeError
- python cx_Oracle: UnicodeEncodeError: 'ascii' codec can't encode charactersPythonOracleUnicodeErrorASCII
- python 解決讀取檔案時格式不支援的總結Python
- golang 讀取切分儲存byte流檔案Golang
- python解壓並讀取檔案Python
- python str與byte轉換 encode decodePython
- 完美解決stack Error: Can‘t find Python executable “python“, you can set the PYTHON env variable.ErrorPython
- Go 自定義日期時間格式解析解決方案 - 解決 `parsing time xx as xx: cannot parse xx as xx` 錯誤Go
- 基於.NET的程式讀取Excel檔案的解決方案Excel
- Supervisor 解決 can't find command *
- 阿里雲 Redis 報出You can't read against a non-read redis.解決方案阿里RedisAI
- python讀取大檔案Python
- python小白檔案讀取Python
- python 讀取文字檔案Python
- Python:Python中文寫入csv檔案出現亂碼問題的解決方案之一Python
- 使用Python讀取PlantUML匯出的XMI檔案Python
- Can't Connect to MySQL Server on IP Address (10061) 錯誤的解決方案MySqlServer
- SpringBoot 解決打包釋出後讀取不到 json 檔案問題Spring BootJSON
- @PropertySource 註解實現讀取 yml 檔案
- python中xlrd庫如何實現檔案讀取?Python
- python如何讀取大檔案Python
- ENVI匯出的tif檔案,python讀取失敗。Python
- 5、中文的輸出(GBK不可對映字元的解決方案)字元
- Invalid byte 3 of 3-byte UTF-8 sequence 解決方案
- Python 讀取HDF5檔案Python