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

UnicodeDecodeError psutil.win_service_iter() #866

Closed
FabioBaroni opened this issue Jul 29, 2016 · 6 comments
Closed

UnicodeDecodeError psutil.win_service_iter() #866

FabioBaroni opened this issue Jul 29, 2016 · 6 comments

Comments

@FabioBaroni
Copy link

I have this function for retrieving and displaying info about all the Windows services.

def enum_service():
    for service in psutil.win_service_iter():
        sinfo = service.as_dict()
        print("[*] Name: {} Display name: {} Status: {} Type: {} Path: ".format(sinfo["name"], sinfo["display_name"], sinfo["status"], sinfo["start_type"], sinfo["binpath"]))

I get an error at line 342 of psutil_pswindows.py, in win_service_iter
for name, display_name in cext.winservice_enumerate():
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xe0 in position 7: invalid continuation byte

It seems that one or more values aren't encoded in utf-8 so it throws an error.
Is it a known issue? Can it be fixed?

@giampaolo
Copy link
Owner

Does the error occur on print()? If so then it's cmd.exe's fault, not psutil's.
You should be able to print that by repr()ing it first.

@FabioBaroni
Copy link
Author

I'm not sure I'm doing right but I tried this:

def enum_service():
    for service in psutil.win_service_iter():
        sinfo = service.as_dict()
        print("[*] Name: {} Display name: {} Status: {} Type: {} Path: ".format(repr(sinfo["name"]), repr(sinfo["display_name"]), repr(sinfo["status"]), repr(sinfo["start_type"]), repr(sinfo["binpath"])))

I simply added repr() to each item that I want to display but I get the same error as above.
Since it's just a few lines of code, I'd be grateful if you could run it on your pc and try to debug it in order to rule out any issue on psutil side.

@giampaolo
Copy link
Owner

If you remove the print() and only do service.as_dict() do you still get the unicode error?
If you do then it's a psutil issue, if you don't then it's the cmd.exe encoding which is not able to print that unicode string.

@FabioBaroni
Copy link
Author

I tried again with the following code:

import psutil

for service in psutil.win_service_iter():
    service.as_dict()

I get the same error:

Traceback (most recent call last):
  File "<input>", line 1, in <module>
  File "C:\Users\Fabio\AppData\Local\Programs\Python\Python35\lib\site-packages\psutil\_pswindows.py", line 342, in win_service_iter
    for name, display_name in cext.winservice_enumerate():
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xe0 in position 7: invalid continuation byte

I'm testing this code on Windows 10 with python 3.5.2 . I tried to run the script from the IDE (I'm using PyCharm anyway it shouldn't be important mentioning that) and also using the Python Console. The same error is displayed.

@giampaolo
Copy link
Owner

OK, then it's a psutil problem.

@giampaolo
Copy link
Owner

giampaolo commented Aug 1, 2016

OK I should have fixed it. Can you please compile from sources and verify it is fixed? If not I can attach a .exe pre-compiled version for you to test (Python version? 32 or 64 bit?).

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

No branches or pull requests

2 participants