This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: urllib2 and proxy
Type: Stage:
Components: Library (Lib) Versions: Python 2.2
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: jhylton Nosy List: jhylton, jjlee, jmdesprez
Priority: normal Keywords:

Created on 2003-01-02 11:32 by jmdesprez, last changed 2022-04-10 16:06 by admin. This issue is now closed.

Messages (2)
msg13803 - (view) Author: Jean-Marc Desprez (jmdesprez) Date: 2003-01-02 11:32
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
msg13804 - (view) Author: John J Lee (jjlee) Date: 2003-10-30 19:07
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.
History
Date User Action Args
2022-04-10 16:06:05adminsetgithub: 37684
2003-01-02 11:32:44jmdesprezcreate