views:

116

answers:

2

Hallo,

I wrote a script that works with a proxy (py2.6x):

proxy_support = urllib2.ProxyHandler({'http' : 'http://127.0.0.1:80'})

But in py3.11x there is no urllib2 just a urllib... and that doesnt support the ProxyHandler

How can I use a proxy with urllib? Isnt Python 3 newer then Python 2? Why did they remove urllib2 in a newer version?

+1  A: 

It became urllib.request.ProxyHandler.

2to3 can do this for you.

Matthew Flaschen
+1  A: 

In Python 3 urllib2.ProxyHandleris nowurllib.request.ProxyHandler.

import urllib.request
proxy_support = urllib.request.ProxyHandler({'http' : 'http://127.0.0.1:80'})

Many of the old url*libs have been merge to theurllib package. Here is a great explanation.

abenthy