This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author mingus
Recipients docs@python, mingus
Date 2013-09-03.17:30:20
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1378229420.77.0.30621022035.issue18914@psf.upfronthosting.co.za>
In-reply-to
Content
The python documentation links to an outside website for info and examples on http basic auth. This documentation is terrible and confusing. The link should be removed, and user's should be advised to use the Requests library.


# this example is from http://www.voidspace.org.uk/python/articles/authentication.shtml
# which is linked to by the official python docs http://docs.python.org/2/howto/urllib2.html

import urllib2
 
theurl = 'http://www.someserver.com/toplevelurl/somepage.htm'
username = 'johnny'
password = 'XXXXXX'
# a great password
 
passman = urllib2.HTTPPasswordMgrWithDefaultRealm()
# this creates a password manager
passman.add_password(None, theurl, username, password)
# because we have put None at the start it will always
# use this username/password combination for  urls
# for which `theurl` is a super-url
 
authhandler = urllib2.HTTPBasicAuthHandler(passman)
# create the AuthHandler
 
opener = urllib2.build_opener(authhandler)
 
urllib2.install_opener(opener)
# All calls to urllib2.urlopen will now use our handler
# Make sure not to include the protocol in with the URL, or
# HTTPPasswordMgrWithDefaultRealm will be very confused.
# You must (of course) use it when fetching the page though.
 
pagehandle = urllib2.urlopen(theurl)
# authentication is now handled automatically for us
History
Date User Action Args
2013-09-03 17:30:20mingussetrecipients: + mingus, docs@python
2013-09-03 17:30:20mingussetmessageid: <1378229420.77.0.30621022035.issue18914@psf.upfronthosting.co.za>
2013-09-03 17:30:20minguslinkissue18914 messages
2013-09-03 17:30:20minguscreate