[Python-bugs-list] [ python-Bugs-661042 ] urllib2 and proxy

SourceForge.net noreply@sourceforge.net
Mon, 03 Feb 2003 11:25:37 -0800


Bugs item #661042, was opened at 2003-01-02 11:32
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=661042&group_id=5470

>Category: Python Library
Group: Python 2.2.2
Status: Open
Resolution: None
Priority: 5
Submitted By: Jean-Marc Desprez (jmdesprez)
>Assigned to: Jeremy Hylton (jhylton)
Summary: urllib2 and proxy

Initial Comment:
the following code fails to open the url, through a
proxy (it tries to connect directly, as if no proxy was
supplied) 

#! /usr/bin/env python
import urllib2
if __name__ == "__main__":
        h_prox = urllib2.ProxyHandler({'http' :
'http://10.4.4.123:3128'})
        #opner = urllib2.build_opener(h_prox,
urllib2.HTTPHandler)
        opner = urllib2.build_opener(h_prox)
        urllib2.install_opener(opner)
        urllib2.urlopen('http://www.python.org')

but it works if I add ' urllib2.HTTPHandler' in
build_opener call (commented line)

It seems that 'urllib2:build_opener' calls first
'urllib2:OpenerDirector.add_handler' with all default
handlers (including HTTPhandler when not supplied in
'build_opener'), and after the user supplied
handlers,so the proxy handler is linked in second
position in 'OpenerDirector.handle_open['http'],
whereas it should be first in the open chain.

I checked my theory with a quick and dirty hack in
'add_handler', to force instance of ProxyHandler to be
inserted first in the handler_open['http'] list (it
works), but I think a more apropriated fix shoud be
done in 'build_opener'

regards

----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=661042&group_id=5470