Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
Back to tool/Back to issues
#54377·salt

how to do with file line on windows

Author: kussatomCreated Sep 2, 2019Updated Sep 29, 2026
Labelsbugseverity-lowWindowsConfirmed

Description of Issue

i need to deal with line of file on windows,but failed. it seems the coding problem

Setup

i use the python api and the file.line module:

local.cmd(tgt=s,fun='file.line',arg=[filepath],kwarg={'content':contents,'mode':'ensure','before':"</configuration>"})

get error report

The minion function caused an exception: Traceback (most recent call last):\n  File "c:\\salt\\bin\\lib\\site-packages\\salt\\minion.py", line 1660, in _thread_return\n    return_data = minion_instance.executors[fname](opts, data, func, args, kwargs)\n  File "c:\\salt\\bin\\lib\\site-packages\\salt\\executors\\direct_call.py", line 12, in execute\n    return func(*args, **kwargs)\n  File "c:\\salt\\bin\\lib\\site-packages\\salt\\modules\\file.py", line 2050, in line\n    path_content = salt.utils.data.decode_list(fp_.read().splitlines(True))\nUnicodeDecodeError: \'gbk\' codec can\'t decode byte 0x84 in position 586: illegal multibyte sequence\n

Versions Report

Salt Version:
           Salt: 2019.2.0

Dependency Versions:
           cffi: 1.12.3
       cherrypy: Not Installed
       dateutil: Not Installed
      docker-py: Not Installed
          gitdb: Not Installed
      gitpython: Not Installed
          ioflo: Not Installed
         Jinja2: 2.10.1
        libgit2: 0.28.2
        libnacl: Not Installed
       M2Crypto: Not Installed
           Mako: Not Installed
   msgpack-pure: Not Installed
 msgpack-python: 0.6.1
   mysql-python: Not Installed
      pycparser: 2.19
       pycrypto: 2.6.1
   pycryptodome: Not Installed
         pygit2: 0.28.2
         Python: 3.6.8 (default, Apr 25 2019, 21:02:35)
   python-gnupg: Not Installed
         PyYAML: 5.1.2
          PyZMQ: 18.0.2
           RAET: Not Installed
          smmap: Not Installed
        timelib: Not Installed
        Tornado: 4.5.3
            ZMQ: 4.3.1

System Versions:
           dist: centos 7.6.1810 Core
         locale: UTF-8
        machine: x86_64
        release: 3.10.0-957.27.2.el7.x86_64
         system: Linux
        version: CentOS Linux 7.6.1810 Core

Source: saltstack/salt

View original on GitHubView discussion on GitHub