1

I have Ubuntu as an ec2 instance on AWS, where I hosted a Django application using Apache2 and mod_wsgi. In my code I am trying to get the username through os.environ['USERNAME'] statement, which returns a KeyError: 'USERNAME', how can I get the username?

I want that username because I need to set permissions for a sqlite datebase file, since I cann't know the username, therefore cann't set the permissions on that file.

qurban
  • 3,885
  • 24
  • 36
  • 1
    possible duplicate of: https://stackoverflow.com/questions/3042304/how-to-determine-what-user-and-group-a-python-script-is-running-as – Walucas Apr 02 '19 at 12:16

1 Answers1

0

You may try os.environ["USER"] it would return your current user from environment variables.

Alternatively you may try following to get current user by using getpass

import getpass

getpass.getuser() # This would return current user.
Devang Padhiyar
  • 3,427
  • 2
  • 22
  • 42