Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError: environment can only contain strings with Python 3 on Windows #1

Closed
mrliptontea opened this issue Nov 5, 2017 · 1 comment

Comments

@mrliptontea
Copy link

Hi,

First of all, I'm very glad to see this project still live! Keep up the good work. 🥇

I have an issue to report but luckily also some solutions for it.

Issue:

Triggering CodeIntel results in an error that I found in codeintel.log:

Traceback (most recent call last):
  [...]
  File "site-packages\codeintel\codeintel2\lang_php.py", line 980, in _php_info_from_php
    p = process.ProcessOpen(argv, env=env.get_all_envvars())
  File "site-packages\codeintel\process.py", line 581, in __init__
    creationflags=flags)
  File "subprocess.py", line 709, in __init__
    restore_signals, start_new_session)
  File "site-packages\codeintel\process.py", line 399, in _execute_child
    startupinfo)

TypeError: environment can only contain strings

My environment:

  • Windows 10 64-bit
  • Python 3.6.3 64-bit, tried also on Python 3.5 32-bit
  • Sublime Text Build 3153 from Dev channel

Solution

The culprit is this bit of code:

if env:
encoding = sys.getfilesystemencoding()
_enc_env = {}
for key, value in env.items():
try:
_enc_env[key.encode(encoding)] = value.encode(encoding)
except UnicodeEncodeError:
# Could not encode it, warn we are dropping it.
log.warn("Could not encode environment variable %r "
"so removing it", key)

While it is necessary for Python 2, it is breaking in 3 because all keys and values end up being encoded as bytes.

I'm not sure what's the best approach here, I came up with:

  1. Add if six.PY2 at line 499
  2. Check if key/value is not isinstance(value, string_types) and encode only then.

Similar has been done in django/django@fc6b90b.

@Kronuz
Copy link
Member

Kronuz commented Nov 7, 2017

Thank you! This should be fixed now in v2.0.0-rc.2 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants