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\", line 170, in _run_module_as_main
    "__main__", mod_spec)
  File "C:\Python34\lib\", line 85, in _run_code
    exec(code, run_globals)
  File "C:\Dev\testenv\Scripts\tox.exe\", line 9, in <module>
  File "C:\Dev\testenv\lib\site-packages\tox\", line 39, in main
    retcode = Session(config).runcommand()
  File "C:\Dev\testenv\lib\site-packages\tox\", line 373, in runcommand
    return self.subcommand_test()
  File "C:\Dev\testenv\lib\site-packages\tox\", line 530, in subcommand_test
    self.installpkg(venv, path)
  File "C:\Dev\testenv\lib\site-packages\tox\", line 473, in installpkg
    venv.installpkg(path, action)
  File "C:\Dev\testenv\lib\site-packages\tox\", line 240, in installpkg
    self._install([sdistpath], extraopts=extraopts, action=action)
  File "C:\Dev\testenv\lib\site-packages\tox\", line 304, in _install
  File "C:\Dev\testenv\lib\site-packages\tox\", line 277, in run_install_command
    self._pcall(argv, cwd=self.envconfig.config.toxinidir, action=action)
  File "C:\Dev\testenv\lib\site-packages\tox\", line 375, in _pcall
    redirect=redirect, ignore_ret=ignore_ret)
  File "C:\Dev\testenv\lib\site-packages\tox\", line 123, in popen, self.msg, args, env))
  File "C:\Python34\lib\encodings\", 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, the script runs successfully:

for k,v in env.items():
    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