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

Decoding error on child.connections(kind='unix') #675

Closed
teto opened this issue Aug 28, 2015 · 13 comments
Closed

Decoding error on child.connections(kind='unix') #675

teto opened this issue Aug 28, 2015 · 13 comments

Comments

@teto
Copy link

teto commented Aug 28, 2015

Here is a log of my small python script that tries to find the unix socket associated with the neovim application running in the currently focused terminal:

NVIM detected
Retreived terminal pid 13109, nvim should be one of its children
proc name rxvt-unicode with 5 children
child name & pid rxvt-unicode/13110
child name & pid zsh/13111
child name & pid nvim/13272
Could not find neovim socket 'utf-8' codec can't decode byte 0xd7 in position 469: invalid continuation byte
Traceback (most recent call last):
  File "/home/teto/.i3/i3nvim.py", line 56, in get_nvim_socket
    unix_sockets = child.connections(kind="unix")
  File "/home/teto/.local/lib/python3.4/site-packages/psutil/__init__.py", line 1010, in connections
    return self._proc.connections(kind)
  File "/home/teto/.local/lib/python3.4/site-packages/psutil/_pslinux.py", line 709, in wrapper
    return fun(self, *args, **kwargs)
  File "/home/teto/.local/lib/python3.4/site-packages/psutil/_pslinux.py", line 1169, in connections
    ret = _connections.retrieve(kind, self.pid)
  File "/home/teto/.local/lib/python3.4/site-packages/psutil/_pslinux.py", line 555, in retrieve
    for fd, family, type_, laddr, raddr, status, bound_pid in ls:
  File "/home/teto/.local/lib/python3.4/site-packages/psutil/_pslinux.py", line 508, in process_unix
    f.readline()  # skip the first line
  File "/usr/lib/python3.4/codecs.py", line 319, in decode
    (result, consumed) = self._buffer_decode(data, self.errors, final)
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xd7 in position 469: invalid continuation byte

The exception seem to start with the child.connections(kind="unix") call. On another computer with configuration nearly identical (same $HOME, ubuntu on both etc...) the script works perfectly. I've tried with the latest master and still the same error.

@giampaolo
Copy link
Owner

Mmm this is gonna be hard to debug. What's the output of sys.getfilesystemencoding() and sys.getdefaultencoding()? Do you have the same problem by using python 2? Also, what's the output of echo $LANG?

@teto
Copy link
Author

teto commented Aug 30, 2015

$ echo $LANG
fr_FR.UTF-8
$ python3
>>> import sys
>>> sys.getfilesystemencoding()
'utf-8'

It works with python2. The typical neovim socket name looks like "/tmp/nvimeArb4h/0"

@teto
Copy link
Author

teto commented Aug 30, 2015

let me know if psutil embeds a logging system I could enable to help debugging

@giampaolo
Copy link
Owner

What about sys.getdefaultencoding()?

@teto
Copy link
Author

teto commented Aug 30, 2015

Oops sorry: sys.getdefaultencoding() gives 'utf-8'

giampaolo added a commit that referenced this issue Aug 30, 2015
@giampaolo
Copy link
Owner

Please try e229dbe

@giampaolo
Copy link
Owner

Actually please try 77119eb

@teto
Copy link
Author

teto commented Aug 31, 2015

Apparently the commit fixed it. Hope it's not because the random socket name was ok. Anyway I close this and will reopen if the bug arises again.
thanks

@teto teto closed this as completed Aug 31, 2015
@teto teto reopened this Aug 31, 2015
@teto
Copy link
Author

teto commented Aug 31, 2015

Sorry, it was working because I had left python2 in the shebang. When using python3 I still have the same mistake

2935   File "/usr/local/lib/python3.4/dist-packages/psutil-3.2.0-py3.4-linux-x86_64.egg/psutil/__init__.
     py", line 1010, in connections                                                                     
2936     return self._proc.connections(kind)                                                            
2937   File "/usr/local/lib/python3.4/dist-packages/psutil-3.2.0-py3.4-linux-x86_64.egg/psutil/_pslinux.
     py", line 720, in wrapper                                                                          
2938     return fun(self, *args, **kwargs)                                                              
2939   File "/usr/local/lib/python3.4/dist-packages/psutil-3.2.0-py3.4-linux-x86_64.egg/psutil/_pslinux.
     py", line 1176, in connections                                                                     
2940     ret = _connections.retrieve(kind, self.pid)                                                    
2941   File "/usr/local/lib/python3.4/dist-packages/psutil-3.2.0-py3.4-linux-x86_64.egg/psutil/_pslinux.
     py", line 566, in retrieve                                                                         
2942     for fd, family, type_, laddr, raddr, status, bound_pid in ls:                                  
2943   File "/usr/local/lib/python3.4/dist-packages/psutil-3.2.0-py3.4-linux-x86_64.egg/psutil/_pslinux.
     py", line 519, in process_unix                                                                     
2944     f.readline()  # skip the first line                                                            
2945   File "/usr/lib/python3.4/codecs.py", line 319, in decode                                         
2946     (result, consumed) = self._buffer_decode(data, self.errors, final)                             
2947 UnicodeDecodeError: 'utf-8' codec can't decode byte 0xeb in position 3019: invalid continuation    
     byte                                                           

@giampaolo
Copy link
Owner

Can you paste the content of the file (with cat or something)?

@giampaolo
Copy link
Owner

Actually it would be great if you can attach the file itself. Can you mail it to me at [email protected]?

@giampaolo
Copy link
Owner

Please try now.

@teto
Copy link
Author

teto commented Aug 31, 2015

Great that solved it. Thanks again ! Closing this (Hopefully definitely :) )

@teto teto closed this as completed Aug 31, 2015
mrjefftang added a commit to mrjefftang/psutil that referenced this issue Sep 2, 2015
* giampaolo/master: (34 commits)
  pre-release updates
  try to fix appveyor failure
  refactor setup.py + fix Makefile
  fix OSX test failure
  linux / setup.py: do not print warnings
  giampaolo#675: [Linux] net_connections(); UnicodeDecodeError may occur when listing UNIX sockets
  move unicode tests so that they are executed on all platforms
  skip failing test on appveyor
  try to fix appveyor failure
  test refactoring+
  try to fix appveyor failures
  open files by using sys.getfilesystemencoding() + refactor stuff
  giampaolo#675: try to fix encoding issue
  fix python 3 compilation error
  giampaolo#659: [Linux] compilation error on Suse 10. (patch by maozguttman)
  make flake8 happy
  fix giampaolo#644: add support for CTRL_* signals on Windows
  str-encode NIC names
  always return encoded strings instead of unicode
  giampaolo#650: make cmdline() handle unicode on python 2
  ...
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