strange problem with os.getlogin

Alex Martelli aleaxit at yahoo.com
Mon Sep 20 10:39:18 EDT 2004


Michele Simionato <michele.simionato at gmail.com> wrote:

> I am having a strange issue with os.getlogin on Mandrake 10:
> 
> $ python -c "import os; print os.getlogin()"
> Traceback (most recent call last):
>   File "<string>", line 1, in ?
> OSError: [Errno 2] No such file or directory
> 
> On another linux machine (Debian) instead it works as expected.
> For the moment I am using os.popen("whoami").read() which works
> but it is an hack :-( 
> Does anybody have an idea of the source of the problem?

Try running that python -c under strace (with the appropriate flags set
to avoid excessive tracing... you really care about tracing 'open'
syscalls, maybe 'access' or 'readlink'...) to see what getlogin is
trying to open.  On my Mandrake 9.2, it tries /var/run/utmpx, which
fails, then /var/run/utmp, which succeeds.  I don't have a 10.0 handy to
try... (I had installed it on the 'toy machine' but then I installed
ubuntu on top of it recently;-).


Alex



More information about the Python-list mailing list