Python Forum
Trying to get REMOTE_USER enviroment varibale's value
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Trying to get REMOTE_USER enviroment varibale's value
#1
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?
Reply
#2
# 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.
Reply
#3
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?
Reply
#4
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?
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Syntax errors: Struggling to setup enviroment and load packages AH56 5 2,785 Jun-30-2021, 01:01 PM
Last Post: AH56
  Assign the sum of 2 consecutive numbers in a list to a varibale Fenaz 3 2,111 Apr-05-2020, 10:30 PM
Last Post: bowlofred

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020