[Baypiggies] TypeError in os.path.realpath

Lincoln Peters anfrind at gmail.com
Wed May 30 18:33:36 CEST 2012

I'm developing a Python tool to monitor some of our Linux servers (running
RHEL 5.6 and Python 2.4).  In some cases, I need to track down the
executable file for a running process, which I should be able to by
resolving the symlink at /proc/<PID>/cmd.  When I use the "readlink"
command at the shell, it works correctly, but sometimes when I call
os.path.realpath with the exact same path, I get a TypeError the following
traceback (note: copied by hand since the servers have no Internet access):

File "/usr/lib64/python2.4/posixpath.py", line 423, in realpath
  resolved = _resolve_link(component)
File "/usr/lib64/python2.4/posixpath.py", line 440, in _resolve_link
  while islink(path):
File "/usr/lib64/python2.4/posixpath.py", line 159, in islink
  st = os.lstat(path)
TypeError: lstat() argument 1 must be (encoded string without NULL bytes),
not str

Strangely, this only happens with some processes and not others, and I
can't discern any pattern.  Any thoughts?

Thanks in advance.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/baypiggies/attachments/20120530/ec8ac178/attachment.html>

More information about the Baypiggies mailing list