Try this:<div><br></div><div>try:</div><div> do_whatever()</div><div>except TypeError:</div><div> print "The original whatever was %r" % whatever_piece_of_data</div><div><br></div><div>If you need to, hack posixpath.py itself.</div>
<div><br></div><div>-jj</div><div><br><div class="gmail_quote">On Wed, May 30, 2012 at 9:33 AM, Lincoln Peters <span dir="ltr"><<a href="mailto:anfrind@gmail.com" target="_blank">anfrind@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><p>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):</p>
<p>File "/usr/lib64/python2.4/posixpath.py", line 423, in realpath<br>
resolved = _resolve_link(component)<br>
File "/usr/lib64/python2.4/posixpath.py", line 440, in _resolve_link<br>
while islink(path):<br>
File "/usr/lib64/python2.4/posixpath.py", line 159, in islink<br>
st = os.lstat(path)<br>
TypeError: lstat() argument 1 must be (encoded string without NULL bytes), not str</p>
<p>Strangely, this only happens with some processes and not others, and I can't discern any pattern. Any thoughts?</p>
<p>Thanks in advance.</p>
<br>_______________________________________________<br>
Baypiggies mailing list<br>
<a href="mailto:Baypiggies@python.org">Baypiggies@python.org</a><br>
To change your subscription options or unsubscribe:<br>
<a href="http://mail.python.org/mailman/listinfo/baypiggies" target="_blank">http://mail.python.org/mailman/listinfo/baypiggies</a><br></blockquote></div><br><br clear="all"><div><br></div>-- <br>In this life we cannot do great things. We can only do small things with great love. -- Mother Teresa<br>
</div>