Python Forum
Trying to get REMOTE_USER enviroment varibale's value - 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: Trying to get REMOTE_USER enviroment varibale's value (/thread-1857.html)



Trying to get REMOTE_USER enviroment varibale's value - nikos - Jan-30-2017

Hello,

I'm trying to grab the http auth username in order for a user to be able to download a file from a basic http auth protected folder as follows:

realfile = form.getvalue('realfile')
authuser = os.environ.get( 'REMOTE_USER', 'Άγνωστος' )

#here we enter in case the user selected a file fro download
if realfile:
# Give user the file he requested
print( '''<meta http-equiv="REFRESH" content="5; URL=../data/files/%s">''' % realfile ) 

Why in your opinion is this happening?
Is it due to the way of "<metahttp-equiv .." that is obstructing this, in a way that when this statemnt executes it sends new headers lossing existing env vars?


RE: Trying to get REMOTE_USER enviroment varibale's value - nikos - Jan-31-2017

# Give user the file requested
url = "http://superhost.gr/data/files/%s" % realfile

user, password = 'user', 'passwd'

r = requests.get( url, auth = (user, password) ) # send auth unconditionally
r.raise_for_status()
Trying to make this work i have up with this.
But the problem when i run my cgi script is that it DOES NOT ASK the user for his HTTP Basic Auth User & Pass combo.

Can someone make this work please? What am i missing?

ps. 1: Forgot to to mention that ".../files" is a basic http auth protected folder that needs valid user & pass info.
ps. 2: The simplest answer would be the better. Thank you.


RE: Trying to get REMOTE_USER enviroment varibale's value - nikos - Feb-01-2017

Hello please someone answer me!

How must i write the above snippet in order for HTTP auth to actually ASK for the User & Pass combo instead of prior knowing it?


RE: Trying to get REMOTE_USER enviroment varibale's value - micseydel - Feb-01-2017

The reason you haven't gotten a response is that your question is unclear. Your subject line implies you just want an environment variable, but it sounds like from the body of your posts that you actually want to prompt the user for credentials when the visit a webpage in a browser?

What libraries or modules are you using? Can you reproduce this problem with 10-20 lines of code that we could run ourselves?