salt: UnicodeEncodeError: 'ascii' codec can't encode characters

I use file.recurse to transfer directories and files,once the file name contains chinese,there will be problems,those files couldn’t be transfered to the spectified minions.debug info shows “UnicodeEncodeError: ‘ascii’ codec can’t encode characters in position 31-34: ordinal not in range(128)”.

Here are my .sls: test1: file.recurse: - name: /root/group2test - source: salt://release/test/{{pillar["test"]}} - mkdirs: True - include_empty: True

Here are the debug info:

      ID: test1
Function: file.recurse
    Name: /root/group2test
  Result: False
 Comment: An exception occurred in this state: Traceback (most recent call last):
            File "/usr/lib/python2.6/site-packages/salt/state.py", line 1746, in call
              **cdata['kwargs'])
            File "/usr/lib/python2.6/site-packages/salt/loader.py", line 1703, in wrapper
              return f(*args, **kwargs)
            File "/usr/lib/python2.6/site-packages/salt/states/file.py", line 2807, in recurse
              manage_file(dest, src)
            File "/usr/lib/python2.6/site-packages/salt/states/file.py", line 2685, in manage_file
              **pass_kwargs)
            File "/usr/lib/python2.6/site-packages/salt/states/file.py", line 1814, in managed
              __env__
            File "/usr/lib/python2.6/site-packages/salt/modules/file.py", line 3490, in source_list
              contextkey = '{0}_|-{1}_|-{2}'.format(source, source_hash, saltenv)
          UnicodeEncodeError: 'ascii' codec can't encode characters in position 31-34: ordinal not in range(128)
 Started: 20:08:21.608398
Duration: 1467.811 ms
 Changes:   

Summary for g146

Succeeded: 0 Failed: 1

Total states run: 1 Total run time: 1.468 s [DEBUG ] jid 20170407133951142263 found all minions set([‘jenkins’, ‘g146’]) ERROR: Minions returned with non-zero exit code

Here are the debug logs: 2017-04-07 14:00:40,412 [salt.utils.event ][DEBUG ][15280] Sending event: tag = file.recurse; data = {‘comment’: ‘An exception occurred in this state: Traceback (most recent call last):\n File “/usr/lib/python2.6/site-packages/salt/state.py”, line 1746, in call\n **cdata['kwargs'])\n File “/usr/lib/python2.6/site-packages/salt/loader.py”, line 1703, in wrapper\n return f(*args, **kwargs)\n File “/usr/lib/python2.6/site-packages/salt/states/file.py”, line 2807, in recurse\n manage_file(dest, src)\n File “/usr/lib/python2.6/site-packages/salt/states/file.py”, line 2685, in manage_file\n **pass_kwargs)\n File “/usr/lib/python2.6/site-packages/salt/states/file.py”, line 1814, in managed\n env\n File “/usr/lib/python2.6/site-packages/salt/modules/file.py”, line 3490, in source_list\n contextkey = '{0}|-{1}|-{2}'.format(source, source_hash, saltenv)\nUnicodeEncodeError: 'ascii' codec can't encode characters in position 31-34: ordinal not in range(128)\n’, ‘_stamp’: ‘2017-04-07T06:00:40.412486’, ‘retcode’: 2, ‘name’: ‘/root/group2test’, ‘start_time’: ‘20:28:36.031209’, ‘result’: False, ‘duration’: 1336.1479999999999, ‘run_num’: 0, ‘changes’: {}, ‘id’: ‘test1’}

Salt Version: Salt: 2016.11.3

Dependency Versions: cffi: Not Installed cherrypy: 3.2.2 dateutil: 1.4.1 gitdb: Not Installed gitpython: Not Installed ioflo: Not Installed Jinja2: 2.8 libgit2: Not Installed libnacl: Not Installed M2Crypto: 0.20.2 Mako: Not Installed msgpack-pure: Not Installed msgpack-python: 0.4.6 mysql-python: 1.2.3c1 pycparser: Not Installed pycrypto: 2.6.1 pygit2: Not Installed Python: 2.6.6 (r266:84292, Aug 18 2016, 15:13:37) python-gnupg: Not Installed PyYAML: 3.10 PyZMQ: 14.3.1 RAET: Not Installed smmap: Not Installed timelib: Not Installed Tornado: 4.2.1 ZMQ: 3.2.5

System Versions: dist: centos 6.8 Final machine: x86_64 release: 2.6.32-642.el6.x86_64 system: Linux version: CentOS 6.8 Final

I not sure if I should modify the default coding that saltstack uesd and don’t know which .py file should be modified. My English is terrible,please forgive me

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Reactions: 1
  • Comments: 18 (14 by maintainers)

Most upvoted comments

Try running the master with export PYTHONIOENCODING=utf8 and salt, salt-call, see if it makes a difference.

If an error happens now it should be "UnicodeEncodeError: 'utf8' codec can't encode characters in position .....".

I have not tried this myself.