Salt is unable to decode unicode character in .ini file via the state
search cancel

Salt is unable to decode unicode character in .ini file via the state

book

Article ID: 323000

calendar_today

Updated On:

Products

VMware VMware Aria Suite

Issue/Introduction

Symptoms:
While reading a .ini file during state execution salt is unable to decode character in ini. file.

Error: 
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>




Environment

VMware vRealize Automation SaltStack Config 8.11.x

Cause

You will see this issue by creating an ini file that contains unicode characters and then trying to read it using Salt.
https://github.com/saltstack/salt/issues/65777

Resolution

This is known issue and it will be fixed in Salt 3007