Maverick icon indicating copy to clipboard operation
Maverick copied to clipboard

如何解决错误 UnicodeDecodeError: 'charmap' codec can't decode byte 0x98 in position 132: character maps to <undefined> decoding with 'windows-1251' codec failed

Open luckypoem opened this issue 1 year ago • 1 comments

hi. 我运行python3 mvrk.py --config ./demo_src/config.py --source_dir ./demo_src/ --build_dir ./dist/ 后,显示:

Site prefix: / Source dir: ./demo_src/ Build dir: ./dist/ Start clean...done. Loading contents... Traceback (most recent call last): File "C:\Users\12799\maverick\Maverick\Utils.py", line 99, in safe_read return f.read() ^^^^^^^^ File "", line 322, in decode UnicodeDecodeError: 'utf-8' codec can't decode byte 0xe7 in position 131943: invalid continuation byte

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "C:\Users\12799\maverick\mvrk.py", line 45, in main() File "C:\Users\12799\maverick\mvrk.py", line 41, in main builder.build_all() File "C:\Users\12799\maverick\Maverick\Builder.py", line 134, in build_all content = Content(content_path) ^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\12799\maverick\Maverick\Content.py", line 30, in init content = safe_read(path) ^^^^^^^^^^^^^^^ File "C:\Users\12799\maverick\Maverick\Utils.py", line 104, in safe_read return content.decode(encoding=encoding) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Python312\Lib\encodings\cp1251.py", line 15, in decode return codecs.charmap_decode(input,errors,decoding_table) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ UnicodeDecodeError: 'charmap' codec can't decode byte 0x98 in position 132: character maps to decoding with 'windows-1251' codec failed

12799@DESKTOP-B6LK9IO MINGW64 ~/maverick$

谢谢回复!

luckypoem avatar Oct 21 '24 16:10 luckypoem

看起来主要是因为你的文件用了无法识别的文件编码,可以尝试转换成常见的编码,比如 utf-8 试试看

AlanDecode avatar Oct 25 '24 11:10 AlanDecode