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

Fix UnicodeEncodeError with non ASCII paths on Windows (Python 2) #1252

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Fix UnicodeEncodeError with non ASCII paths on Windows (Python 2) #1252

wants to merge 2 commits into from

Conversation

BoboTiG
Copy link
Contributor

@BoboTiG BoboTiG commented Mar 21, 2018

OS: Windows.
Python version impacted: 2.

When dealing with non ASCII chars in the path (let's say the username is Mickaël), we are blocked on an unicode error:

======================================================================
FAIL: test_open_files (proc=psutil.Process(pid=2548, name='explorer.exe', started='09:02:04'))
----------------------------------------------------------------------
Traceback (most recent call last):
  File "psutil\tests\test_contracts.py", line 331, in test_fetch_all
	ret = attr(*args, **kwargs)
  File "psutil\__init__.py", line 1133, in open_files
	return self._proc.open_files()
  File "psutil\_pswindows.py", line 635, in wrapper
	return fun(self, *args, **kwargs)
  File "psutil\_pswindows.py", line 882, in open_files
	_file = convert_dos_path(_file)
  File "psutil\_compat.py", line 140, in wrapper
	result = user_function(*args, **kwds)
  File "psutil\_pswindows.py", line 189, in convert_dos_path
	driveletter = cext.win32_QueryDosDevice(rawdrive)
UnicodeEncodeError: 'ascii' codec can't encode character u'\xeb' in position 32: ordinal not in range(128)

Here, rawdrive = '\BaseNamedObjects\C::Users:Mickaël:AppData:Local:Microsoft:Windows:Explorer:thumbcache_32.db!dfMaintainer'.

psutil/_psutil_windows.c Outdated Show resolved Hide resolved
psutil/_psutil_windows.c Outdated Show resolved Hide resolved
@BoboTiG
Copy link
Contributor Author

BoboTiG commented Mar 22, 2018

It still breaks some tests. I do not know if there is a possibile simple fix. Perhaps the good move is to use Python 3.

@BoboTiG
Copy link
Contributor Author

BoboTiG commented Apr 3, 2018

I close the issue, I will switch to Python 3 :)

@BoboTiG BoboTiG closed this Apr 3, 2018
@BoboTiG BoboTiG deleted the fix-windows-unicode-error branch April 3, 2018 12:52
@giampaolo
Copy link
Owner

giampaolo commented Apr 3, 2018 via email

@BoboTiG BoboTiG restored the fix-windows-unicode-error branch April 3, 2018 16:29
@BoboTiG BoboTiG reopened this Apr 3, 2018
@giampaolo
Copy link
Owner

I'm having troubles reproducing this. I tried:

# -*- coding: utf-8 -*- 

import psutil

s = '\BaseNamedObjects\C::Users:Mickaël:AppData:Local:Microsoft:Windows:Explorer:thumbcache_32.db!dfMaintainer'

print(repr(psutil._psplatform.cext.win32_QueryDosDevice(s)))

...but it succeeds returning an empty string.

@gliptak
Copy link
Contributor

gliptak commented Oct 24, 2020

With Python 2.7 EOL, maybe this can be closed

https://www.python.org/downloads/

 Python version Maintenance status First released End of support Release schedule
    2.7 end-of-life 2010-07-03 2020-01-01 PEP 373

@giampaolo
Copy link
Owner

Python 2 downloads are still around 30% and it's not gonna disappear anytime soon:
https://pypistats.org/packages/psutil

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

Successfully merging this pull request may close these issues.

None yet

3 participants