By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,218 Members | 1,194 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,218 IT Pros & Developers. It's quick & easy.

OWA (Outlook Web Access) with urllib2

P: n/a
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
Share this Question
Share on Google+
5 Replies


P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.