Li4n0 / hugo_encryptor

A tools for encrypting hugo posts
155 stars 28 forks source link

windows上python3默认encoding是gbk出错,open()需要加encoding #16

Closed sieveLau closed 3 years ago

sieveLau commented 3 years ago

报错是这样:

> python hugo-encryptor.py   || exit
Traceback (most recent call last):
  File "hugo-encryptor.py", line 133, in <module>
    f.write(str(soup))
UnicodeEncodeError: 'gbk' codec can't encode character '\xa9' in position 2259: illegal multibyte sequence

查了一下,在hugo-encryptor.py的131行的with open(fullpath, 'w') as f:里面加encoding="utf-8",变成:

            with open(fullpath, 'w',encoding="utf-8") as f:
            html = str(soup)
            f.write(str(soup))

以及166行的open也同样加一个encoding,就不报错了。

sieveLau commented 3 years ago

这个问题与 #6 是同一个问题,提交了一个pull request

Li4n0 commented 3 years ago

已merge。感谢反馈。