472,975 Members | 1,819 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

OWA (Outlook Web Access) with urllib2

Hello,

I want to acces my OWA (Outlook Web Acces - http Exchange interface)
server with urllib2 but, when I try, I've always a 401 http error.
Can someone help me (and us)?

Thanks.
here's my pyscript:
( Python 2.3.3 (#1, Apr 6 2004, 01:47:39) - [GCC 3.3.3 (SuSE Linux)]
on linux2 )
************************************************** **********************
#! /usr/bin/python
import urllib2
# set authentification
auth = urllib2.HTTPBasicAuthHandler()
auth.add_password('owa.mydomain', 'http://owa.mydomain/',
'**USERNAME**', '**PASSWORD**')
# don't use proxy
prox = urllib2.ProxyHandler({})
# installation
opener = urllib2.build_opener(prox, auth)
urllib2.install_opener(opener)
# start
url = urllib2.urlopen('http://owa.mydomain/exchange/')
print url.readlines()

************************************************** **********************

here's the traceback:
************************************************** **********************
./owa.py

Traceback (most recent call last):
File "./owa.py", line 22, in ?
url = urllib2.urlopen('http://owa.mydomain/exchange/')
File "/usr/lib/python2.3/urllib2.py", line 129, in urlopen
return _opener.open(url, data)
File "/usr/lib/python2.3/urllib2.py", line 326, in open
'_open', req)
File "/usr/lib/python2.3/urllib2.py", line 306, in _call_chain
result = func(*args)
File "/usr/lib/python2.3/urllib2.py", line 901, in http_open
return self.do_open(httplib.HTTP, req)
File "/usr/lib/python2.3/urllib2.py", line 895, in do_open
return self.parent.error('http', req, fp, code, msg, hdrs)
File "/usr/lib/python2.3/urllib2.py", line 352, in error
return self._call_chain(*args)
File "/usr/lib/python2.3/urllib2.py", line 306, in _call_chain
result = func(*args)
File "/usr/lib/python2.3/urllib2.py", line 412, in
http_error_default
raise HTTPError(req.get_full_url(), code, msg, hdrs, fp)
urllib2.HTTPError: HTTP Error 401: Accès refusé
************************************************** **********************

here's the LiveHTTPheaders/Firefox debug:
( the web page is well delivered )
************************************************** **********************
http://owa.mydomain/exchange/

GET /exchange/ HTTP/1.1
Host: owa.mydomain
User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.7)
Gecko/20040804 Firefox/0.9.3
Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5
Accept-Language: en-us,en;q=0.5
Accept-Encoding: gzip,deflate
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive: 300
Connection: keep-alive

HTTP/1.x 401 Accès refusé
Server: Microsoft-IIS/5.0
Date: Thu, 23 Sep 2004 08:56:03 GMT
WWW-Authenticate: Negotiate
WWW-Authenticate: NTLM
WWW-Authenticate: Basic realm="owa.mydomain"
Connection: close
Content-Length: 21
Content-Type: text/html

GET /exchange/ HTTP/1.1
Host: owa.mydomain
User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.7)
Gecko/20040804 Firefox/0.9.3
Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5
Accept-Language: en-us,en;q=0.5
Accept-Encoding: gzip,deflate
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive: 300
Connection: keep-alive
Authorization: Basic CGFYZW50CDPOC3FTEXAQKG==

HTTP/1.x 200 OK
Server: Microsoft-IIS/5.0
Date: Thu, 23 Sep 2004 08:56:15 GMT
Set-Cookie: sessionid=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx,0x409;
path=/exchange/
Content-Type: text/html
Content-Length: 1071
MS-WebStorage: 6.0.6249
Cache-Control: no-cache

************************************************** **********************
Jul 18 '05 #1
5 7339
pa***********@free.fr (Pascal) writes:
I want to acces my OWA (Outlook Web Acces - http Exchange interface)
server with urllib2 but, when I try, I've always a 401 http error. [...] here's the LiveHTTPheaders/Firefox debug:

[...]

So, what does urllib2 send? Use ethereal, for example.
John
Jul 18 '05 #2
This is the Python ~ IIS dialogue (with Ethereal / Follow TCP stream):

GET /exchange/ HTTP/1.0
Host: owa.mydomain
User-agent: Python-urllib/2.1

HTTP/1.1 401 Accès refusé
Server: Microsoft-IIS/5.0
Date: Mon, 27 Sep 2004 10:44:28 GMT
WWW-Authenticate: Negotiate
WWW-Authenticate: NTLM
WWW-Authenticate: Basic realm="owa.mydomain"
Content-Length: 21
Content-Type: text/html

Urllib2 didn't try to send authentification after http 401 error.
Jul 18 '05 #3
pa***********@free.fr (Pascal) writes:
This is the Python ~ IIS dialogue (with Ethereal / Follow TCP stream):

GET /exchange/ HTTP/1.0
Host: owa.mydomain
User-agent: Python-urllib/2.1

HTTP/1.1 401 Accès refusé
Server: Microsoft-IIS/5.0
Date: Mon, 27 Sep 2004 10:44:28 GMT
WWW-Authenticate: Negotiate
WWW-Authenticate: NTLM
WWW-Authenticate: Basic realm="owa.mydomain"
Content-Length: 21
Content-Type: text/html

Urllib2 didn't try to send authentification after http 401 error.


Well, there's your problem <0.5 wink>.

Seriously:

1. Test your code with Python 2.4a3. Quite possible that this is a
fixed bug.

2. If that doesn't work, debug urllib2.
HTTPPasswordMgr.find_user_password() looks a good place to stick
some print statements. Also, the method of
AbstractBasicAuthHandler. It's only a few lines of code!
John
Jul 18 '05 #4
Effectively, if you look at http://python.org/2.4/NEWS.html you can
see that
urllib2 now recognizes Basic authentication even if other
authentication schemes are offered.

In LiveHTTPheaders/Firefox debug, there is
WWW-Authenticate: Negotiate
WWW-Authenticate: NTLM
WWW-Authenticate: Basic realm="owa.mydomain"
and the basic authentification is the last proposed.

So now, how can I force basic authentification with urllib2 (without
using Python 2.4a)?
Jul 18 '05 #5
pa***********@free.fr (Pascal) wrote in message news:<e5**************************@posting.google. com>...
Effectively, if you look at http://python.org/2.4/NEWS.html you can
see that
urllib2 now recognizes Basic authentication even if other
authentication schemes are offered.

In LiveHTTPheaders/Firefox debug, there is
WWW-Authenticate: Negotiate
WWW-Authenticate: NTLM
WWW-Authenticate: Basic realm="owa.mydomain"
and the basic authentification is the last proposed.

So now, how can I force basic authentification with urllib2 (without
using Python 2.4a)?


You can do manual basic authentication.
See http://aspn.activestate.com/ASPN/Coo.../Recipe/305288

Regards,

Fuzzy

http://www.voidspace.org.uk/atlantib...thonutils.html
Jul 18 '05 #6

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

Similar topics

4
by: O. Koch | last post by:
Until now, i know that ftplib doesn't support proxies and that i have to use urllib2. But i don't know how to use the urllib2 correct. I found some examples, but i don't understand them. Is...
4
by: bmiras | last post by:
I've got a problem using urllib2 to get a web page. I'm going through a proxy using user/password authentification and i'm trying to get a page asking for a HTTP authentification. And I'm using...
1
by: Matthew Wilson | last post by:
I am writing a script to check on my router's external IP address. My ISP refreshes my IP very often and I use dyndns for the hostname for my computer. My Netgear mr814 router has a webserver that...
2
by: John F Dutcher | last post by:
Can anyone comment on why the code shown in the Python error is in some way incorrect...or is there a problem with Python on my hoster's site ?? The highlites don't seem to show here...but line...
0
by: jacob c. | last post by:
When I request a URL using urllib2, it appears that urllib2 always makes the request using HTTP 1.0, and not HTTP 1.1. I'm trying to use the "If-None-Match"/"ETag" HTTP headers to conserve...
0
by: Ali.Sabil | last post by:
hello all, I just maybe hit a bug in both urllib and urllib2, actually urllib doesn't support proxy authentication, and if you setup the http_proxy env var to...
3
by: m.banaouas | last post by:
Hi all, I started to use urllib2 library and HTTPBasicAuthHandler class in order to authenticate with a http server (Zope in this case). I don't know why but it doesn't work, while authenticating...
0
by: dvd | last post by:
Hi i have a python script that uses urllib2 to download one file, it runs ok in any pc but when urlopen is called in the ipod it show the following error: <urlopen error (4, 'Non-recoverable...
2
by: silk.odyssey | last post by:
I am getting the following error trying to download an html page using urllib2. urllib2.HTTPError: HTTP Error 204: NoContent The url is of this type: ...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
4
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...

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.