Python Forum
Client OS username - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: Client OS username (/thread-21301.html)



Client OS username - ImPyBoy17 - Sep-23-2019

Hi All,
I have a flask application, would like to fetch the OS username by default for creating a registration portal. I don’t want the users to provide username as Input.

Please let me know how can we grab this value !?


RE: Client OS username - ndc85430 - Sep-23-2019

Firstly, why do you need this information?

Secondly, this isn't really a Python question. Remember that the Python code runs on the client and not the server. Client-side code is written in JavaScript (or something that can be transpiled to JS). Having said that, this is likely going to be difficult to do - browsers aren't going to allow you much access to the underlying OS as that would be quite a security risk, wouldn't it?

You could of course write a desktop app or another web app that runs on the machine and communicates with the server by means of an HTTP API.


RE: Client OS username - Axel_Erfurt - Sep-23-2019

in python

import getpass 
username = getpass. getuser() 
print(username)



RE: Client OS username - ndc85430 - Sep-23-2019

Did you miss the part about this being a web app? The server side code isn't, in general, going to be running on the client machine..


RE: Client OS username - Malt - Sep-24-2019

(Sep-23-2019, 06:01 PM)ImPyBoy17 Wrote: Hi All,
I have a flask application, would like to fetch the OS username by default for creating a registration portal. I don’t want the users to provide username as Input.

Please let me know how can we grab this value !?

OS username, you mean? Login username?

If yes, we can grep them using
import os
print(os.getlogin())



RE: Client OS username - buran - Sep-24-2019

@Malt, OP is asking about getting username logged in on the client OS, not the server-side