HTTPBasicAuthHandler doesn't work

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • nicolas.surribas@gmail.com

    #1

    HTTPBasicAuthHandler doesn't work

    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 !

  • John J. Lee

    #2
    Re: HTTPBasicAuthHa ndler doesn't work

    nicolas.surriba s@gmail.com writes:
    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
    :-(
    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:

    The official home of the Python Programming Language



    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/authentificatio n/authentication/ :-)

    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)):
    More Pythonic for checklink to raise ValueError here than return
    non-zero.

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

    Better to use module urlparse.


    John

    Comment

    Working...