Python3 using requests to grab HTTP Auth Data

Νίκος Βέργος me.on.nzt at gmail.com
Wed Feb 1 19:00:33 EST 2017


Τη Πέμπτη, 2 Φεβρουαρίου 2017 - 1:51:52 π.μ. UTC+2, ο χρήστης Ian έγραψε:
> On Wed, Feb 1, 2017 at 2:51 PM, Νίκος Βέργος <me.on.nzt at gmail.com> wrote:
> > Τη Τετάρτη, 1 Φεβρουαρίου 2017 - 11:41:28 μ.μ. UTC+2, ο χρήστης Michael Torrie έγραψε:
> >> On 02/01/2017 01:51 PM, Νίκος Βέργος wrote:
> >> > as well as input() for both user & pass combo but iam not getting in chrome the basic pop-up HTTP auth window.
> >> >
> >> > Any idea why?
> >>
> >> What you're describing is not something you can do with an interactive
> >> Python script.  HTTP-level authentication is requested of your browser
> >> by the web server itself.  On Apache there are numerous methods you can
> >> use.  Individual users can use .htaccess directives to add
> >> authentication to a directory, for example.  You'll need to learn about it:
> >> https://www.google.com/search?q=apache+http+authentication
> >>
> >> If you're using a framework like Django, there are mechanisms for
> >> checking the username and password against a Python method.  Again,
> >> google for http authentication and whatever framework you're using.
> >>
> >> I once used a special python script that was called by an Apache module
> >> to verify users against a customized LDAP filter.  Again, that involves
> >> server cooperation though a module.
> >>
> >> In general, the browser pops up the username and password box in
> >> response to a request from the web server.  It's not something your CGI
> >> script can just do without some cooperation from the web server.
> >
> > I used to have this workaround solution for triggering the web server to pop-up the HTTP Auth window
> >
> > print '''<meta http-equiv="refresh" content="2;url=http://superhost.gr/data/files/%s">''' % file_requested
> >
> > and i have tried to read the the login auth name that user entered by using
> >
> > authuser = os.environ.get( 'REMOTE_USER', 'Άγνωστος' )
> >
> > unfortunately it always failes to receive it that's why i'm trying to do the trick with the requests module.
> 
> Fails how? It doesn't ask the user, or the environment variable is empty?
> 
> requests is an HTTP client library. It's not very useful server-side
> unless you're talking to other servers. It is, in any case,
> nonsensical to send an HTTP request to the browser.

<met-equiv> triggers the http auth windows, so the user can enter the auth info, i just cant seem to grab the auth username back.



More information about the Python-list mailing list