bumpversion icon indicating copy to clipboard operation
bumpversion copied to clipboard

TypeError: environment can only contain strings

Open wooyek opened this issue 9 years ago • 5 comments

The commit command after is failing on windows and PY3. Can anybody help with this?

Traceback (most recent call last):
  File "c:\Python35\lib\runpy.py", line 170, in _run_module_as_main
    "__main__", mod_spec)
  File "c:\Python35\lib\runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "D:\projekty\github\django-pascal-templates\.pve\Scripts\bumpversion.exe\__main__.py", line 9, in <module>
  File "d:\projekty\github\django-pascal-templates\.pve\lib\site-packages\bumpversion\__init__.py", line 994, in main
    vcs.commit(message=commit_message)
  File "d:\projekty\github\django-pascal-templates\.pve\lib\site-packages\bumpversion\__init__.py", line 73, in commit
    list(os.environ.items()) + [(b'HGENCODING', b'utf-8')]
  File "c:\Python35\lib\subprocess.py", line 629, in check_output
    **kwargs).stdout
  File "c:\Python35\lib\subprocess.py", line 696, in run
    with Popen(*popenargs, **kwargs) as process:
  File "c:\Python35\lib\subprocess.py", line 950, in __init__
    restore_signals, start_new_session)
  File "c:\Python35\lib\subprocess.py", line 1220, in _execute_child
    startupinfo)
TypeError: environment can only contain strings

wooyek avatar Apr 04 '16 20:04 wooyek

I ran into the same issue and I think the problem is that the environment strings are being coded as bytes instead of strings.

I'm going to test that and create a pull request.

smsearcy avatar Apr 28 '16 00:04 smsearcy

Same problem, and I can confirm.

Running under Python 3.5.2

Using byte strings

>>> subprocess.check_output(["cmd"], env=dict(list(os.environ.items()) + [(b'HGENCODING', b'utf-8')]))
Traceback (most recent call last):
  File "<pyshell#9>", line 1, in <module>
    subprocess.check_output(["cmd"], env=dict(list(os.environ.items()) + [(b'HGENCODING', b'utf-8')]))
  File "C:\Users\davidfallah\AppData\Local\Programs\Python\Python35-32\lib\subprocess.py", line 626, in check_output
    **kwargs).stdout
  File "C:\Users\davidfallah\AppData\Local\Programs\Python\Python35-32\lib\subprocess.py", line 693, in run
    with Popen(*popenargs, **kwargs) as process:
  File "C:\Users\davidfallah\AppData\Local\Programs\Python\Python35-32\lib\subprocess.py", line 947, in __init__
    restore_signals, start_new_session)
  File "C:\Users\davidfallah\AppData\Local\Programs\Python\Python35-32\lib\subprocess.py", line 1224, in _execute_child
    startupinfo)
TypeError: environment can only contain strings

Using regular strings

>>> subprocess.check_output(["cmd"], env=dict(list(os.environ.items()) + [('HGENCODING', 'utf-8')]))
b'Microsoft Windows [Version 6.1.7601]\r\nCopyright (c) 2009 Microsoft Corporation.  All rights reserved.\r\n\r\nC:\\Users\\davidfallah\\AppData\\Local\\Programs\\Python\\Python35-32>'

Running under Python 2.7.10

Using byte strings

subprocess.check_output(["cmd"], env=dict(list(os.environ.items()) + [(b'HGENCODING', b'utf-8')]))
'Microsoft Windows [Version 6.1.7601]\r\nCopyright (c) 2009 Microsoft Corporation.  All rights reserved.\r\n\r\nC:\\Python27>'

Using regular strings

>>> subprocess.check_output(["cmd"], env=dict(list(os.environ.items()) + [('HGENCODING', 'utf-8')]))
'Microsoft Windows [Version 6.1.7601]\r\nCopyright (c) 2009 Microsoft Corporation.  All rights reserved.\r\n\r\nC:\\Python27>'

TAGC avatar Sep 21 '16 09:09 TAGC

is there any resolution/work around please?

kvamshk avatar Nov 04 '16 19:11 kvamshk

Same issue here. Is there any news ?

vcorreze avatar Jan 24 '18 10:01 vcorreze

Try https://github.com/c4urself/bump2version

wooyek avatar Jan 29 '18 07:01 wooyek