Author stefan.richthofer
Recipients jamesmudd, pguermo, stefan.richthofer, zyasoft
Date 2017-02-20.15:44:58
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
I see this too, but it even fails in CPython for me:

Python 2.7.12 (default, Nov 19 2016, 06:48:10) 
[GCC 5.4.0 20160609] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import os
>>> os.getlogin()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
OSError: [Errno 2] No such file or directory

Did you check if os.getlogin works in CPython?

Then I found the following:

(Yes it is rather old, but it seems to cover the error I observe.)

So, given that os.getlogin is supposed to be a thin wrapper for (?) Jython's behavior might actually be right if that call fails due to other reasons. Only the error message might better be more sophisticated.

That said, it would be trivial to build some fallbacks into PosixModule.getlogin, e.g.:

    public static PyObject getlogin() {
        String login = posix.getlogin();
        if (login == null) {
            login = System.getenv("LOGNAME");
        if (login == null) {
            login = System.getenv("USER");
        if (login == null) {
            login = System.getProperty("");
        return new PyString(login);

    public static PyObject getlogin() {
        return new PyString(posix.getlogin());
(posix is JNR's posix-wrapper)

However os.getlogin shall only work on terminal/live console if at all, which would not hold then any more. So code using this to detect console-mode would break (bad way for detection anyway?).
So maybe we should better keep it that way, like a thin wrapper and apply such fallbacks on Python-level, i.e. os.getenv('LOGNAME'), os.getenv('USER'), os.getenv('USERNAME') (windows)

I am actually undecided, because I favor portable wrappers and guess these fallbacks could prevent failures in naive real-world existing code.

Date User Action Args
2017-02-20 15:44:59stefan.richthofersetmessageid: <>
2017-02-20 15:44:59stefan.richthofersetrecipients: + stefan.richthofer, zyasoft, jamesmudd, pguermo
2017-02-20 15:44:59stefan.richthoferlinkissue2534 messages
2017-02-20 15:44:58stefan.richthofercreate