[BUG] file.append: UnicodeDecodeError: 'charmap' codec can't decode byte 0x8d in position
PacGyver opened this issue · comments
Description
I use the file.append module to add a line to a file. A Windows minion reports the following error:
File "C:\Program Files\Salt Project\Salt\bin\Lib\site-packages\salt-3004.1-py3.8.egg\salt\states\file.py", line 6225, in append
nlines = nlines.decode(__salt_system_encoding__)
File "c:\Program Files\Salt Project\Salt\bin\lib\encodings\cp1252.py", line 15, in decode
return codecs.charmap_decode(input,errors,decoding_table)
UnicodeDecodeError: 'charmap' codec can't decode byte 0x8d in position 1987: character maps to <undefined>
Setup
Linux Salt Master: Debian 10.12 with Docker Image "saltstack/salt"
salt 3004.1
Windows Minion 3004.1-1
Testfile on Windows Minion
Content:
Ã
Steps to Reproduce the behavior
state.apply
Expected behavior
Line "LocalConsent=64" is appended
Screenshots
If applicable, add screenshots to help explain your problem.
Versions Report
salt --versions-report
3004.1file.append:
- name: 'c:\testfile'
- text: 'LocalConsent=64'
Additional context
Notepad++ shows the Windows Files as UTF-8 encoded. If I change the line 122 in salt_init_.py from
setattr(builtins, "salt_system_encoding", encoding)
to
setattr(builtins, "salt_system_encoding", "mbcs")
or to
setattr(builtins, "salt_system_encoding", "utf-8")
everything works as expected.
Hi there! Welcome to the Salt Community! Thank you for making your first contribution. We have a lengthy process for issues and PRs. Someone from the Core Team will follow up as soon as possible. In the meantime, here’s some information that may help as you continue your Salt journey.
Please be sure to review our Code of Conduct. Also, check out some of our community resources including:
- Community Wiki
- Salt’s Contributor Guide
- Join our Community Slack
- IRC on LiberaChat
- Salt Project YouTube channel
- Salt Project Twitch channel
There are lots of ways to get involved in our community. Every month, there are around a dozen opportunities to meet with other contributors and the Salt Core team and collaborate in real time. The best way to keep track is by subscribing to the Salt Community Events Calendar.
If you have additional questions, email us at saltproject@vmware.com. We’re glad you’ve joined our community and look forward to doing awesome things with you!