sarugaku / shellingham

Tool to Detect Surrounding Shell

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

UnicodeDecodeError occurs when the Chinese character exists in some processes

paulzhn opened this issue · comments

When I run the command pipenv install, the exception is thrown:

Traceback (most recent call last):
  File "c:\users\tianx\appdata\local\programs\python\python38-32\lib\runpy.py", line 192, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "c:\users\tianx\appdata\local\programs\python\python38-32\lib\runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "C:\Users\tianx\AppData\Local\Programs\Python\Python38-32\Scripts\pipenv.exe\__main__.py", line 4, in <module>
  File "c:\users\tianx\appdata\local\programs\python\python38-32\lib\site-packages\pipenv\__init__.py", line 47, in <module>
    from .cli import cli
  File "c:\users\tianx\appdata\local\programs\python\python38-32\lib\site-packages\pipenv\cli\__init__.py", line 3, in <module>
    from .command import cli
  File "c:\users\tianx\appdata\local\programs\python\python38-32\lib\site-packages\pipenv\cli\command.py", line 7, in <module>
    import crayons
  File "C:\Users\tianx\AppData\Local\Programs\Python\Python38-32\Lib\site-packages\pipenv\patched\crayons.py", line 49, in <module>
    is_powershell = "powershell" in shellingham.detect_shell()[0]
  File "C:\Users\tianx\AppData\Local\Programs\Python\Python38-32\Lib\site-packages\pipenv\vendor\shellingham\__init__.py", line 22, in detect_shell
    shell = get_shell(pid, max_depth=max_depth)
  File "C:\Users\tianx\AppData\Local\Programs\Python\Python38-32\Lib\site-packages\pipenv\vendor\shellingham\nt.py", line 100, in get_shell
    processes = dict(_iter_process())
  File "C:\Users\tianx\AppData\Local\Programs\Python\Python38-32\Lib\site-packages\pipenv\vendor\shellingham\nt.py", line 78, in _iter_process
    info = {'executable': str(pe.szExeFile.decode('utf-8'))}
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xbf in position 0: invalid start byte

And after I changed utf-8 to gbk in 78L, shellingham\nt.py, the problem seemed to be solved. Since this line of code is used to get the processes in the system, I guess that it's the Chinese characters in the process name that cause this problem.

There should be a way to get the canonical encoding since we are using Windows API here. I’ll try to investigate. Thanks for the report.

It seems that Pipenv is using an old version. The fix has been implemented in c30072e and available since 1.2.8.