I need to get the windows login username in my Flask app which is deployed in AWS EC2 instance.
Asked
Active
Viewed 163 times
1
-
Possible duplicate of [Is there a portable way to get the current username in Python?](https://stackoverflow.com/questions/842059/is-there-a-portable-way-to-get-the-current-username-in-python) – jweyrich Oct 08 '19 at 12:40
1 Answers
0
Hmm, I'm assuming your Flask application is running on a Windows EC2 instance and you want to get the login username on the local instance that it is running on? In that case, it really should be as simple as retrieving it from the environment variables, for example using this python snippet:
import os
USER = os.getenv('USERNAME')
Ashaman Kingpin
- 1,467
- 1
- 11
- 11
-
Sorry, forgot to mention it is running on ubuntu. when i use the usual command lines i am getting only ubuntu as user. But i need to get the local machine (windows login username) when i share the App with users. I used the below command but still i am not able to fetch the windows user login, is there any way to communicate with windows machine from ubuntu EC2. import getpass getpass.getuser() – nerdy panda Oct 08 '19 at 13:20
-
Still not quite clear on your requirement. Are you saying you are developing on Linux but your users will deploy the app in a Windows environment and in that environment you want to determine the window user login name? – Ashaman Kingpin Oct 08 '19 at 13:32
-
So then what I suggested should work. Try and deploy the app in a Windows environment and the code snippet I provided should get you the login name of the user that is running the app. – Ashaman Kingpin Oct 08 '19 at 14:07
-
i deployed my flask app in windows environment as you suggested, i ran the app using port 80. While i tried to access it through shared system(user point of view) i am not able to access using ec2 ipv4 address – nerdy panda Oct 11 '19 at 12:48
-
What do you mean by shared system(user point of view)? Are you using the ec2 public IP address or private IP address? I would suggest trying to access it from the instance itself first using its private IP address to at least confirm the app is running (if you are not doing so already). – Ashaman Kingpin Oct 11 '19 at 12:57
-
sorry about the late reply, the app is running on public ip address and its working fine. But when i share the app to other users they are not able to access it using the public ip address – nerdy panda Oct 12 '19 at 10:53
-
If the app is running on their own system, why would it have the same public IP address as the app running on your system? – Ashaman Kingpin Oct 12 '19 at 11:49