Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > HTTPBasicAuthHandler doesn't work

Reply
Thread Tools

HTTPBasicAuthHandler doesn't work

 
 
nicolas.surribas@gmail.com
Guest
Posts: n/a
 
      07-09-2006
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 !

 
Reply With Quote
 
 
 
 
John J. Lee
Guest
Posts: n/a
 
      07-09-2006
http://www.velocityreviews.com/forums/(E-Mail Removed) 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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
RE;Kontki if you delete kontiki any program you loaded with it in it 'will not work I have tried it with three programs and none work anymore (if you se it just stop download) 1-Twitch Computer Support 5 04-23-2009 02:45 PM
urllib2 HTTPBasicAuthHandler and resumingbroken downloads Brendan Python 4 08-25-2008 12:42 PM
urllib2 and HTTPBasicAuthHandler m.banaouas Python 3 01-17-2007 04:37 AM
MS work around on text wrapping in a datagrid does not work TB ASP .Net 2 02-22-2006 10:34 PM
Hi I am new to asp i can not get it to work on xp pro sp2 even though the localhost work but asp pages dont so can some one help craig dicker ASP .Net 9 07-07-2005 11:52 AM



Advertisments