【Python】問題解決:'cp950' codec can't decode byte 0xe6 in position 111: illegal multibyte sequence

前言

此為以下問題的解決方法筆記:

'cp950' codec can't decode byte 0xe6 in position 111: illegal multibyte sequence

解法

簡單說就是 encoding 的問題,
在開啟對應檔案時加入「encoding=“utf-8”」即可以解決。
(注意檔案 open 的地方)

範例

原本你的程式可能長這樣 (注意 open 的地方)

with open(each_file, 'r') as fin:
        jf = json.load(fin)

請改成這樣

with open(each_file, 'r', encoding="utf-8") as fin:
        jf = json.load(fin)

Reference

https://wongwongnotes-github-io.pages.dev/debug_error/cp950-codec/

https://oxygentw.net/blog/computer/python-file-utf8-encoding/

Licensed under CC BY-NC-SA 4.0