473,325 Members | 2,308 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,325 software developers and data experts.

Authentication from urllib2

I'm trying to do Basic authentication using urllib2 and
HTTPPasswordMgr Objects.

According to my understanding I ought to perform the following simple
sequence (except it doesn't work). Can someone cast their eyes over it
and see what I'm doing wrong please.............

import urllib2

theurl = 'http://www.somerestrictedserver.com'
username = 'somebody'
password = 'XXXXX' # a great password
therealm = 'theRealm'

passman = urllib2.HTTPPasswordMgr()
passman.add_password(therealm, theurl, username, password)

authhandler = urllib2.HTTPBasicAuthHandler(passman)
opener = urllib2.build_opener(authhandler)

req = urllib2.Request(theurl)
filehandle = opener.open(req)
print filehandle.read()

Ideally I would like to use HTTPPasswordMgrWithDefaultRealm() and
specify None for the realm. I would also like to install the opener
and just use urllib2.urlopen rather than using the opener directly.

When I run this I still get a 401 HTTPError. I would expect the opener
to recognise the realm and retry the request (handle the error using
hte handler I have provided..).

Regards,
Fuzzy
http://www.voidspace.org.uk/atlantib...thonutils.html

Jul 18 '05 #1
1 3750
Aaargh.. that was annoying... much searching on the net to work this one out.
No thanks to you lot though ;-)

theurl = 'http://www.somerestrictedserver.com'
passman = urllib2.HTTPPasswordMgr()
passman.add_password(therealm, theurl, username, password)

*won't* work.
theurl starts with the protocol http:// which isn't what HTTPPasswordMgr needs.

theurl = 'www.somerestrictedserver.com'

works...

Regards,
Fuzzy

http://www.voidspace.org.uk/atlantib...thonutils.html
Fuzzyman <fu******@gmail.com> wrote in message news:<sr********************************@4ax.com>. ..
I'm trying to do Basic authentication using urllib2 and
HTTPPasswordMgr Objects.

According to my understanding I ought to perform the following simple
sequence (except it doesn't work). Can someone cast their eyes over it
and see what I'm doing wrong please.............

import urllib2

theurl = 'http://www.somerestrictedserver.com'
username = 'somebody'
password = 'XXXXX' # a great password
therealm = 'theRealm'

passman = urllib2.HTTPPasswordMgr()
passman.add_password(therealm, theurl, username, password)

authhandler = urllib2.HTTPBasicAuthHandler(passman)
opener = urllib2.build_opener(authhandler)

req = urllib2.Request(theurl)
filehandle = opener.open(req)
print filehandle.read()

Ideally I would like to use HTTPPasswordMgrWithDefaultRealm() and
specify None for the realm. I would also like to install the opener
and just use urllib2.urlopen rather than using the opener directly.

When I run this I still get a 401 HTTPError. I would expect the opener
to recognise the realm and retry the request (handle the error using
hte handler I have provided..).

Regards,
Fuzzy
http://www.voidspace.org.uk/atlantib...thonutils.html

Jul 18 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Andre Bocchini | last post by:
I'm having some trouble using proxy authentication. I can't figure out how to authenticate with a Squid proxy. I know for a fact the proxy is using Basic instead of Digest for the authentication....
7
by: luigipaioro | last post by:
Good morning to all! I'm trying to access on a web page that needs user and password authentication. I'm enabled to access there (I mean that I have an user name and a password to access via...
7
by: Michael Foord | last post by:
#!/usr/bin/python -u # 15-09-04 # v1.0.0 # auth_example.py # A simple script manually demonstrating basic authentication. # Copyright Michael Foord # Free to use, modify and relicense. #...
0
by: Pieter Edelman | last post by:
Hi all, I'm trying to submit some data using a POST request to a HTTP server with BASIC authentication with python, but I can't get it to work. Since it's driving me completely nuts, so here's...
1
by: news.corp.adobe.com | last post by:
I need to perform basic authentication and I also need to be able to use the put and delete methods to copy files / delete files on a server. Here is how I successfully perform basic...
2
by: john | last post by:
I'm trying to access the XML version of my Tivo now playing list with python. It uses auth digest HTTP authentication. I could really use some help! I'm able to get this page using curl: curl...
2
by: trapeze.jsg | last post by:
Hi. Is there anybody who have tried to use python to access Microsofts MapPoint soap services? I am trying hard but I have run into a big thick wall called md5 digest authentication. The...
1
by: Ray Slakinski | last post by:
Hello, I have defined a function to set an opener for urllib2, this opener defines any proxy and http authentication that is required. If the proxy has authencation itself and requests an...
4
by: looping | last post by:
Hi, I have to make internet connections through an ISA proxy server that use NTLM or Kerberos authorization method. I've found a program in python called ntlmaps that act like a proxy and could...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.