Non-ascii environment variables causes tox script to fail

Issue #264 on hold
Delano Rodgers created an issue

Tox version: 2.1.1 Python version: 3.4 OS: Windows 8.1


When running to tox script, I get this error:

Traceback (most recent call last):
  File "C:\Python34\lib\runpy.py", line 170, in _run_module_as_main
    "__main__", mod_spec)
  File "C:\Python34\lib\runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "C:\Dev\testenv\Scripts\tox.exe\__main__.py", line 9, in <module>
  File "C:\Dev\testenv\lib\site-packages\tox\session.py", line 39, in main
    retcode = Session(config).runcommand()
  File "C:\Dev\testenv\lib\site-packages\tox\session.py", line 373, in runcommand
    return self.subcommand_test()
  File "C:\Dev\testenv\lib\site-packages\tox\session.py", line 530, in subcommand_test
    self.installpkg(venv, path)
  File "C:\Dev\testenv\lib\site-packages\tox\session.py", line 473, in installpkg
    venv.installpkg(path, action)
  File "C:\Dev\testenv\lib\site-packages\tox\venv.py", line 240, in installpkg
    self._install([sdistpath], extraopts=extraopts, action=action)
  File "C:\Dev\testenv\lib\site-packages\tox\venv.py", line 304, in _install
    action=action)
  File "C:\Dev\testenv\lib\site-packages\tox\venv.py", line 277, in run_install_command
    self._pcall(argv, cwd=self.envconfig.config.toxinidir, action=action)
  File "C:\Dev\testenv\lib\site-packages\tox\venv.py", line 375, in _pcall
    redirect=redirect, ignore_ret=ignore_ret)
  File "C:\Dev\testenv\lib\site-packages\tox\session.py", line 123, in popen
    self.id, self.msg, args, env))
  File "C:\Python34\lib\encodings\cp1252.py", line 19, in encode
    return codecs.charmap_encode(input,self.errors,encoding_table)[0]
UnicodeEncodeError: 'charmap' codec can't encode character '\ufffd' in position 2486: character maps to <undefined>

However, when I add this code just before the last line in the _pcall function in venv.py, the script runs successfully:

for k,v in env.items():
    try:
        v.encode('ascii')
    except UnicodeEncodeError:
        env[k] =  v.encode('ascii', errors='ignore').decode('ascii')

thus leading me to believe that tox isn't liking the non-ascii characters in some of my environment variables.

Are there any workarounds for this?

Comments (3)

  1. Delano Rodgers reporter

    Upon further checking, I found that an installer put a '\ufffd' (replacement mark) inside my user path, which I'm guessing is what threw off tox. I fixed the mark and now it works fine.

  2. Log in to comment