Hi !
I'm trying to add the HTTP basic authentificatio n to my web spider but
it doesn't work...
The HTTPBasicAuthHa ndler don't send the headers for authentificatio n
:-(
Here is the code : http://devloop.lyua.org/releases/lswww_urllib2.py
def
__init__(self,r ooturl,firsturl =[],forbidden=[],proxy={},cooki e="",auth_basic =[]):
root=rooturl
self.excluded=f orbidden
self.proxy=prox y
self.cookie=coo kie
self.auth_basic =auth_basic
if root[-1]!="/":
root+="/"
if(self.checkli nk(root)):
print "Invalid link argument"
sys.exit(0)
for lien in firsturl:
if(self.checkli nk(lien)):
print "Invalid link argument"
sys.exit(0)
server=(root.sp lit("://")[1]).split("/")[0]
self.root=root
self.server=ser ver
director = urllib2.OpenerD irector()
director.add_ha ndler(urllib2.H TTPHandler())
director.add_ha ndler(urllib2.H TTPSHandler())
if self.proxy!={}:
director.add_ha ndler(urllib2.P roxyHandler(sel f.proxy))
if self.auth_basic !=[]:
auth=urllib2.HT TPBasicAuthHand ler(urllib2.HTT PPasswordMgrWit hDefaultRealm() )
auth.add_passwo rd(None, self.root, self.auth_basic[0],
self.auth_basic[1])
director.add_ha ndler(auth)
if self.cookie!="" :
cj = cookielib.LWPCo okieJar()
if os.path.isfile( self.cookie):
cj.load(self.co okie,ignore_dis card=True)
director.add_ha ndler(urllib2.H TTPCookieProces sor(cj))
urllib2.install _opener(directo r)
Where is the problem ?
Thanks !
I'm trying to add the HTTP basic authentificatio n to my web spider but
it doesn't work...
The HTTPBasicAuthHa ndler don't send the headers for authentificatio n
:-(
Here is the code : http://devloop.lyua.org/releases/lswww_urllib2.py
def
__init__(self,r ooturl,firsturl =[],forbidden=[],proxy={},cooki e="",auth_basic =[]):
root=rooturl
self.excluded=f orbidden
self.proxy=prox y
self.cookie=coo kie
self.auth_basic =auth_basic
if root[-1]!="/":
root+="/"
if(self.checkli nk(root)):
print "Invalid link argument"
sys.exit(0)
for lien in firsturl:
if(self.checkli nk(lien)):
print "Invalid link argument"
sys.exit(0)
server=(root.sp lit("://")[1]).split("/")[0]
self.root=root
self.server=ser ver
director = urllib2.OpenerD irector()
director.add_ha ndler(urllib2.H TTPHandler())
director.add_ha ndler(urllib2.H TTPSHandler())
if self.proxy!={}:
director.add_ha ndler(urllib2.P roxyHandler(sel f.proxy))
if self.auth_basic !=[]:
auth=urllib2.HT TPBasicAuthHand ler(urllib2.HTT PPasswordMgrWit hDefaultRealm() )
auth.add_passwo rd(None, self.root, self.auth_basic[0],
self.auth_basic[1])
director.add_ha ndler(auth)
if self.cookie!="" :
cj = cookielib.LWPCo okieJar()
if os.path.isfile( self.cookie):
cj.load(self.co okie,ignore_dis card=True)
director.add_ha ndler(urllib2.H TTPCookieProces sor(cj))
urllib2.install _opener(directo r)
Where is the problem ?
Thanks !
Comment