h91d7 / python-ntlm

Automatically exported from code.google.com/p/python-ntlm
0 stars 0 forks source link

Ensure HTTP status results are handled tranparently, as usual in urllib2 #1

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. Try to retrieve a ntlm secured url that redirects to a second url
2. Currently only the first response to the first url is retrieved
3. The response then needs to be processed to locate the second url

What is the expected output? What do you see instead?
I expect to see the reponse from the second url

Original issue reported on code.google.com by Matthijs.Mullender on 10 Dec 2008 at 9:03

GoogleCodeExporter commented 8 years ago

Original comment by Matthijs.Mullender on 10 Dec 2008 at 9:03

GoogleCodeExporter commented 8 years ago
I created a python 2.6 modification of your library to fix this a while ago (I 
was 
working on a site that heavily used redirects). Attached is a diff of my 
changes that is 
intended to solve this issue.

I created two methods to replace your single NTLM authentication method. 
Control is 
transparently handed back to the urllib2 opener between method calls, allowing 
it to 
handle error codes such as 302 redirects.

To keep the connection alive I've lovingly stolen the HTTP handler from the 
urlgrabber library (http://linux.duke.edu/urlgrabber/).

Some caveats:
- I don't copy the undirected headers between requests like you do in your 
original 
library -- I couldn't see a reason to do so.
- I don't add a "Connection: close" header to the final request during NTLM 
communication. It's unneeded as the urlgrabber HTTP handler allows us to keep 
the 
connection open between requests, avoiding unnecessary extra authentication.
- I haven't made a python 3.0 version.
- This hasn't been tested for six months and subsequent modification has 
occurred, 
so it may not work right away. I hope that the diff can at least suggest a 
solution to 
this issue.

Original comment by divinene...@gmail.com on 3 Feb 2010 at 1:43

Attachments: