# 记Windows和macOS默认文件编码不同导致报错

**URL:** <https://forum.beginner.center/t/topic/1792>\
**Category:** 🛠工具与编程\
**Tags:** rimetool\
**Created:** [2025 年3 月 4 日 15:45 UTC](https://forum.beginner.center/t/topic/1792 "2025-03-04T15:45:26Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

作者： ![doggie](https://forum.beginner.center/user_avatar/forum.beginner.center/doggie/32/550_2.png) [@doggie](https://forum.beginner.center/u/doggie)\
发布日期： [2025 年3 月 4 日 15:45 UTC](https://forum.beginner.center/t/topic/1792/1 "2025-03-04T15:45:26Z")

</div>

我的主力机是macOS，前几个版本的rimetool都是用mac开发

今天加入了新伙伴主力是Windows，发现rimetool刚使用就报错，关于编码gbk的报错

```auto

(base) J:\rime>rimetool --input-path J:\rime\rimetool-master\rimetool-master\examples\contacts.vcf --tool vcf 
Traceback (most recent call last):
  File "\\?\E:\Anaconda\Scripts\rimetool-script.py", line 33, in <module>
    sys.exit(load_entry_point('rimetool==0.1.6.2', 'console_scripts', 'rimetool')())
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "E:\Anaconda\Lib\site-packages\rimetool\main.py", line 30, in main
    vcf.main(args.input_path, args.output_path)
  File "E:\Anaconda\Lib\site-packages\rimetool\utils\vcf.py", line 20, in main
    for line in infile:
                ^^^^^^
UnicodeDecodeError: 'gbk' codec can't decode byte 0xa0 in position 422: illegal multibyte sequence

```

我俩沟通一番，猛然想起Windows是默认gbk编码，macOS是默认UTF-8编码，而rimetool目前是没有写死文件的读取和输出是用哪种编码进行的

这就导致我在macOS上用rimetool输出的文件是UTF-8格式，这份文件被他下载到Windows后使用rimetool读取，报错编码错误

后续修bug，把读取和输出编码都写死成某一个就行

# 参考资料

- [目前简体中文的 Windows 系统记事本默认编码是 GBK 吗？ - V2EX](https://www.v2ex.com/t/936616)
- [macOS 和 Windows 之间的文件乱码问题 - Another Dayu](https://anotherdayu.com/2023/5075/)
