Python3 using requests to grab HTTP Auth Data

Chris Angelico rosuav at gmail.com
Wed Feb 1 14:22:32 EST 2017


On Thu, Feb 2, 2017 at 2:10 AM, Νίκος Βέργος <me.on.nzt at gmail.com> wrote:
> # 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()
> ==========================
>
> How can i ASK the user for http auth data and store them isntead of giving them to the script?

You should use the input() function (called raw_input() in Python 2)
for a user name, and the getpass module for the password:

https://docs.python.org/3/library/getpass.html

ChrisA



More information about the Python-list mailing list