Python 2.6 -> Python 3 (ProxyHandler)
Asked Answered
M

2

5

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 doesn't support the ProxyHandler

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

Middlemost answered 26/5, 2010 at 7:54 Comment(0)
G
11

In Python 3, urllib2.ProxyHandler is now urllib.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 merged with theurllib package. Here is a great explanation.

Giuseppinagiustina answered 26/5, 2010 at 8:2 Comment(0)
T
2

It became urllib.request.ProxyHandler.

2to3 can do this for you.

Tusche answered 26/5, 2010 at 7:58 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.