gesomax / httplib2

Automatically exported from code.google.com/p/httplib2
0 stars 0 forks source link

Setting redirections=0 when fetching a resource with a status 303 causes an exception to be thrown instead of returning headers. #59

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. Create a resource that, when POSTed to, returns a 303 with a new
location, and extra HTTP headers that you're interested in inspecting.
2. use httplib2 as follows: responseHeaders, content = httpObj.request(uri,
"POST", body=urlencode(data), redirections=0)

What is the expected output? What do you see instead?

I expect to see my http headers and no content. I'd like to inspect the
headers that come back.

I instead get this exception: "RedirectLimit: Redirected more times than
rediection_limit allows."

What version of the product are you using? On what operating system?

httplib2-0.4.0, patched for python 2.6 (running python 2.6.1), on Mac OS X
10.5.7

Please provide any additional information below.

some context, I guess: in my situation, I'm attempting to write a test
where I first authorize myself at one URI (which returns a 303 to the page
I want to go to after), then make a request with my authorization tokens.
These tokens are stored as cookies, which are set in the 303 response. 
This behaviour works fine in the browser. However, httplib2 auto-resolves
redirects, so I don't have a means to fetch the set-cookie headers.

IMHO, the area of the source code you need to look at is in __init__.py,
line 902, the line that says 'if redirections:'; the else: clause is where
the error is being raised.

Original issue reported on code.google.com by robth...@gmail.com on 15 Jul 2009 at 7:33

GoogleCodeExporter commented 8 years ago
Setting Http.force_exceptions_to_status_code to True should do what you want:

http://httplib2.googlecode.com/hg/doc/html/libhttplib2.html#httplib2.Http.force_
excepti
on_to_status_code

Let me know if it doesn't.

Original comment by joe.gregorio@gmail.com on 15 Jul 2009 at 10:20

GoogleCodeExporter commented 8 years ago
Joe: your suggestion is perfect.  The error lay in my not being able to find the
documentation; the project homepage, which I now see has been updated, linked to
nonexistent documentation, and my reading of the code was obviously not as 
careful as
it ought to have been.

Thank you for your prompt response!
-rh

Original comment by robth...@gmail.com on 16 Jul 2009 at 1:44