Python handling username and password for URL
Question: Messing with Python and I'm trying to use this
<https://updates.opendns.com/nic/update?hostname=>, when you got to the URL it
will prompt a username and password. I've been looking around and I found
something about password managers, so I came up with this:

    
    
    urll = "http://url.com"
    username = "username"
    password = "password"
    
    passman = urllib2.HTTPPasswordMgrWithDefaultRealm()
    
    passman.add_password(None, urll, username, password)
    
    authhandler = urllib2.HTTPBasicAuthHandler(passman)
    
    urllib2 = urllib2.build_opener(authhandler)
    
    pagehandle = urllib.urlopen(urll)
    
    print (pagehandle.read())
    

This all works, but it's prompting the username and password via the command
line, requiring the user's interaction. I want it to automatically enter those
values. What am I doing wrong?


Answer: You could use [requests](http://docs.python-requests.org/en/latest/) instead.
The code is as simple as:

    
    
    import requests
    url = 'https://updates.opendns.com/nic/update?hostname='
    username = 'username'
    password = 'password'
    print(requests.get(url, auth=(username, password)).content)
    

