os.getlogin() raises an exception if the current session cannot be found in the /var/run/utmp file. This can happen if the user is not running from a login shell, e.g. from tmux.
This change tries os.getlogin() but falls back to using either the $LOGNAME
environment variable, or pwd.getpwduid(os.getuid())