title: How do I get the basic authentication username with a cgi python script?
body: <p>Let me preface this by saying I'm an engineer at a big company and am NOT a programmer so I'm sorry if I'm way off. This question has really been tough to google the answer which generally means I'm asking the question terribly. So I'll try to respond to users to work towards a solution if you'll let me.</p>
  
  <p>I've also tagged multiple languages because I'm not sure if this is a javascript solution or a python solution. I apologize.</p>
  
  <p>Basically, when a user fills in a form it runs a python cgi script that stores the information to a database. I want to automate the writing of the username so the user doesn't have to fill it in manually(not for security, just for ease of use)</p>
  
  <p>My program is on an apache RedHat server and in /etc/httpd/conf I have put the following in my httpd.conf file:</p>
  
  <pre><code>&lt;Directory /var/www/html/program&gt;
  ##### LDAP Login #######################
  AuthType Basic
  AuthName "ProbeEng Webserver: Enter Your BIGCOMPANY Username and Password"
  AuthBasicProvider ldap
  AuthzLDAPAuthoritative off
  AuthLDAPURL "ldap://ldap.city.bigcompany.com/ou=mtworkers,o=bigcompany.com?uid"
  
  ##### Require Authentication
  Require valid-user
  
  Order deny,allow
  Allow from all
  
  &lt;/Directory&gt;
  </code></pre>
  
  <p>When users access my program they are required to put in their <em>BIGCOMPANY</em> username and password. How can I send that username through to my python cgi-script. The program they start the form on is also a python cgi-script that generates the html. </p>
  
  <p>I tried the following:</p>
  
  <pre><code>try:
     username = getpass.getuser()
  </code></pre>
  
  <p>But that doesn't seem to work.</p>
  
  <p>Is this possible while using a cgi-script, if so how do I access the user's username?</p>
  
  <p>Thanks</p>