You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Expected behavior
The ini value should be displayed without a stacktrace
Screenshots
(venv) PS C:\src\salt> salt-call --local ini.get_option C:\Temp\test.ini Locales Mapping
[ERROR ] An un-handled exception was caught by Salt's global exception handler:
UnicodeDecodeError: 'charmap' codec can't decode byte 0x81 in position 229: character maps to <undefined>
Traceback (most recent call last):
File "C:\Python310\lib\runpy.py", line 196, in _run_module_as_main
return _run_code(code, main_globals, None,
File "C:\Python310\lib\runpy.py", line 86, in _run_code
exec(code, run_globals)
File "C:\src\salt\venv\Scripts\salt-call.exe\__main__.py", line 7, in <module>
sys.exit(salt_call())
File "C:\src\salt\salt\scripts.py", line 443, in salt_call
client.run()
File "C:\src\salt\salt\cli\call.py", line 50, in run
caller.run()
File "C:\src\salt\salt\cli\caller.py", line 95, in run
ret = self.call()
File "C:\src\salt\salt\cli\caller.py", line 202, in call
ret["return"] = self.minion.executors[fname](
File "C:\src\salt\salt\loader\lazy.py", line 159, in __call__
ret = self.loader.run(run_func, *args, **kwargs)
File "C:\src\salt\salt\loader\lazy.py", line 1245, in run
return self._last_context.run(self._run_as, _func_or_method, *args, **kwargs)
File "C:\src\salt\salt\loader\lazy.py", line 1260, in _run_as
return _func_or_method(*args, **kwargs)
File "C:\src\salt\salt\executors\direct_call.py", line 10, in execute
return func(*args, **kwargs)
File "C:\src\salt\salt\loader\lazy.py", line 159, in __call__
ret = self.loader.run(run_func, *args, **kwargs)
File "C:\src\salt\salt\loader\lazy.py", line 1245, in run
return self._last_context.run(self._run_as, _func_or_method, *args, **kwargs)
File "C:\src\salt\salt\loader\lazy.py", line 1260, in _run_as
return _func_or_method(*args, **kwargs)
File "C:\src\salt\salt\modules\ini_manage.py", line 106, in get_option
inifile = _Ini.get_ini_file(file_name, separator=separator)
File "C:\src\salt\salt\modules\ini_manage.py", line 463, in get_ini_file
inifile.refresh()
File "C:\src\salt\salt\modules\ini_manage.py", line 420, in refresh
inicontents = salt.utils.stringutils.to_unicode(rfh.read())
File "C:\Python310\lib\encodings\cp1252.py", line 23, in decode
return codecs.charmap_decode(input,self.errors,decoding_table)[0]
UnicodeDecodeError: 'charmap' codec can't decode byte 0x81 in position 229: character maps to <undefined>
Versions Report
salt --versions-report
(Provided by running salt --versions-report. Please also mention any differences in master/minion versions.)
Salt Version:
Salt: 3006.5Python Version:
Python: 3.10.9 (tags/v3.10.9:1dd9be6, Dec 6 2022, 20:01:21) [MSC v.1934 64 bit (AMD64)]Dependency Versions:
cffi: 1.14.6cherrypy: 18.6.1dateutil: 2.8.1docker-py: Not Installedgitdb: 4.0.7gitpython: 3.1.37Jinja2: 3.1.2libgit2: Not Installedlooseversion: 1.0.2M2Crypto: Not InstalledMako: Not Installedmsgpack: 1.0.2msgpack-pure: Not Installedmysql-python: Not Installedpackaging: 22.0pycparser: 2.21pycrypto: Not Installedpycryptodome: 3.10.1pygit2: Not Installedpython-gnupg: 0.4.8PyYAML: 6.0.1PyZMQ: 25.0.2relenv: Not Installedsmmap: 4.0.0timelib: 0.2.4Tornado: 4.5.3ZMQ: 4.3.4System Versions:
dist:
locale: cp1252machine: AMD64release: 10system: Windowsversion: 10 10.0.22631 SP0 Multiprocessor Free
Additional context
I can fix the problem by modifying salt/modules.ini_manage.py at line 419. The current line is:
with salt.utils.files.fopen(self.name) as rfh:
If I open the file with the encoding="utf-8" option, then everything works:
with salt.utils.files.fopen(self.name, encoding="utf-8") as rfh:
I'm not sure this is a valid fix though. Feedback welcome.
The text was updated successfully, but these errors were encountered:
The functions should probably all need a ini_encoding keyword argument(which defaults to utf-8) that gets passed to fopen, at least this way, you allow users to override the encoding.
Description
Can't modify an
ini
file that contains unicode characters.Setup
Create an
ini
file with the following content (C:\temp\test.ini
):Please be as specific as possible and give set-up details.
Steps to Reproduce the behavior
Attempt to get the value from the ini file using salt:
Expected behavior
The ini value should be displayed without a stacktrace
Screenshots
Versions Report
salt --versions-report
(Provided by running salt --versions-report. Please also mention any differences in master/minion versions.)Additional context
I can fix the problem by modifying
salt/modules.ini_manage.py
at line 419. The current line is:If I open the file with the
encoding="utf-8"
option, then everything works:I'm not sure this is a valid fix though. Feedback welcome.
The text was updated successfully, but these errors were encountered: