HTTPBasicAuthHandler doesn't work

John J. Lee jjlee at reportlab.com
Sun Jul 9 13:10:43 EDT 2006


nicolas.surribas at gmail.com writes:

> Hi !
> I'm trying to add the HTTP basic authentification to my web spider but
> it doesn't work...
> The HTTPBasicAuthHandler don't send the headers for authentification
> :-(

Hi

Several bugs were fixed with Basic auth in Python 2.5.  I'd be most
grateful if you can verify that your program works with Python 2.5
beta1:

http://www.python.org/download/releases/2.5/


Please let me know either way whether or not it works for you with the
2.5 beta1 (beta2 is coming very soon, so get in quick if you want to
help make sure this works right in future!).

Below are a couple of tips unrelated to your question.


By the way, s/authentification/authentication/ :-)


> Here is the code : http://devloop.lyua.org/releases/lswww_urllib2.py
> 
> def
> __init__(self,rooturl,firsturl=[],forbidden=[],proxy={},cookie="",auth_basic=[]):
> 	root=rooturl
> 	self.excluded=forbidden
> 	self.proxy=proxy
> 	self.cookie=cookie
> 	self.auth_basic=auth_basic
> 	if root[-1]!="/":
> 		root+="/"
> 	if(self.checklink(root)):
> 		print "Invalid link argument"
> 		sys.exit(0)
> 	for lien in firsturl:
> 		if(self.checklink(lien)):

More Pythonic for checklink to raise ValueError here than return
non-zero.


> 			print "Invalid link argument"
> 			sys.exit(0)
> 	server=(root.split("://")[1]).split("/")[0]
[...]

Better to use module urlparse.


John



More information about the Python-list mailing list