Lib/http/client.py: could it return an OSError with the current response?
Hi everybody, Sorry for bothering you, this is my first post to the python-dev ML. While using requests to tunnel a request via a proxy requiring user authentication, I have seen that httplib ( https://hg.python.org/cpython/file/3.5/Lib/http/client.py#l831) raises the message returned by the proxy, along with its status code (407) without including the proxy response. This one could be very interesting to the consumer, since it could contain some useful headers (like the supported authentication schemes). Would it be possible to change the http/client.py behavior in order to raise an exception including the whole response? If you don't see any problem with my proposal, how can I propose a pull request? :-) Thanks in advance, Ivo
If you can do it without breaking existing code that doesn't expect the extra information, please go ahead! For things like this it is typically best to go straight to the bug tracker (bugs.python.org) rather than asking the list first -- if the issue turns out to be controversial or mysterious it's always possible to go to the list later at the advice of the person doing triage in the tracker. On Tue, Aug 30, 2016 at 6:41 AM, Ivo Bellin Salarin <ivo.bellinsalarin@gmail.com> wrote:
Hi everybody,
Sorry for bothering you, this is my first post to the python-dev ML.
While using requests to tunnel a request via a proxy requiring user authentication, I have seen that httplib (https://hg.python.org/cpython/file/3.5/Lib/http/client.py#l831) raises the message returned by the proxy, along with its status code (407) without including the proxy response. This one could be very interesting to the consumer, since it could contain some useful headers (like the supported authentication schemes).
Would it be possible to change the http/client.py behavior in order to raise an exception including the whole response?
If you don't see any problem with my proposal, how can I propose a pull request? :-)
Thanks in advance, Ivo
_______________________________________________ Python-Dev mailing list Python-Dev@python.org https://mail.python.org/mailman/listinfo/python-dev Unsubscribe: https://mail.python.org/mailman/options/python-dev/guido%40python.org
-- --Guido van Rossum (python.org/~guido)
On 30 August 2016 at 13:41, Ivo Bellin Salarin <ivo.bellinsalarin@gmail.com> wrote:
While using requests to tunnel a request via a proxy requiring user authentication, I have seen that httplib (https://hg.python.org/cpython/file/3.5/Lib/http/client.py#l831) raises the message returned by the proxy, along with its status code (407) without including the proxy response. This one could be very interesting to the consumer, since it could contain some useful headers (like the supported authentication schemes).
Here are some existing bug threads which may be relevant: https://bugs.python.org/issue7291 (urllib.request support for handling tunnel authentication) https://bugs.python.org/issue24964 (get tunnel response header fields in http.client)
Would it be possible to change the http/client.py behavior in order to raise an exception including the whole response?
That would be one way, and might be good enough for getting a Proxy-Authenticate value. Although there might be other ways that also: * Allow reading the body (e.g. HTML page) of the error response. IMO an exception instance is the wrong place for this; urllib.error.HTTPError is a bad example. * Allow the tunnel response fields to be obtained even when the request was successful
If you don't see any problem with my proposal, how can I propose a pull request? :-)
Perhaps you can use one of the patches at one of the above bug reports as a starting point. What you want seems to be a prerequisite for Issue 7291 (urllib.request), so maybe we can discuss it there. Or open a new bug to focus on the http.client-only aspect.
participants (3)
-
Guido van Rossum
-
Ivo Bellin Salarin
-
Martin Panter