By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,548 Members | 1,402 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,548 IT Pros & Developers. It's quick & easy.

HTTPBasicAuthHandler doesn't work

P: n/a
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
:-(

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)):
print "Invalid link argument"
sys.exit(0)
server=(root.split("://")[1]).split("/")[0]
self.root=root
self.server=server
director = urllib2.OpenerDirector()

director.add_handler(urllib2.HTTPHandler())
director.add_handler(urllib2.HTTPSHandler())

if self.proxy!={}:
director.add_handler(urllib2.ProxyHandler(self.pro xy))

if self.auth_basic!=[]:
auth=urllib2.HTTPBasicAuthHandler(urllib2.HTTPPass wordMgrWithDefaultRealm())
auth.add_password(None, self.root, self.auth_basic[0],
self.auth_basic[1])
director.add_handler(auth)

if self.cookie!="":
cj = cookielib.LWPCookieJar()
if os.path.isfile(self.cookie):
cj.load(self.cookie,ignore_discard=True)
director.add_handler(urllib2.HTTPCookieProcessor(c j))

urllib2.install_opener(director)

Where is the problem ?
Thanks !

Jul 9 '06 #1
Share this Question
Share on Google+
1 Reply


P: n/a
ni**************@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
Jul 9 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.