New submission from Brian Mingus:

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

----------
assignee: docs@python
components: Documentation
messages: 196854
nosy: docs@python, mingus
priority: normal
severity: normal
status: open
title: Python docs link to terrible outsi
versions: Python 2.7

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue18914>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to