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

SourceForge.net noreply at sourceforge.net
Thu Oct 30 14:07:53 EST 2003


Bugs item #661042, was opened at 2003-01-02 11:32
Message generated for change (Comment added) made by jjlee
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

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

Comment By: John J Lee (jjlee)
Date: 2003-10-30 19:07

Message:
Logged In: YES 
user_id=261020

As for 487471, this should be closed -- a handler_order
attribute was added to solve this a while ago.

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

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



More information about the Python-bugs-list mailing list