os.getlogin() Error

Wildman best_lay at yahoo.com
Sat May 6 12:35:01 EDT 2017


On Fri, 05 May 2017 11:30:41 -0700, 20/20 Lab wrote:

> I'm not sure if this will help you, but I found some stuff on accident 
> looking at something related.
> 
> Not sure if it will help, but looked promising
> 
> https://github.com/parmentelat/apssh/issues/1
> 
> ==Some snippets from the page
> 
>  From the os.getlogin() docs: "Returns the user logged in to the 
> controlling terminal of the process." Your script does not have a 
> controlling terminal when run from cron. The docs go on to suggest: "For 
> most purposes, it is more useful to use the environment variable LOGNAME 
> to find out who the user is, or pwd.getpwuid(os.getuid())[0] to get the 
> login name of the currently effective user id."
> 
> 
> I suggest you to replace os.getlogin with:
> 
> import pwd
> import os
> 
> getlogin = lambda: pwd.getpwuid(os.getuid())[0]
> default_username = getlogin()

I appreciate the reply but the problem has been fixed.

-- 
<Wildman> GNU/Linux user #557453
The cow died so I don't need your bull!



More information about the Python-list mailing list