I'm using urllib2 to interact with a webserver. For the specific problem I need to solve, I need to tunnel the traffic through a proxy. I managed to do that with a urllib2 'ProxyHandler'.
I also need to accept and send cookies. I managed to do that with a urllib2 'cookielib.LWPCookieJar()'.
The problem is that while they work individually, they don't work 'together'. The last opener that I add with 'urllib2.install_opener(opener)' is the one that will work.
Is is possible to have two active 'openers'? Or another way to solve this problem?
Combine proxy handler and cookie processor in a single opener:
cj = cookielib.CookieJar()
opener = build_opener(ProxyHandler({'http': 'ip:port'}), HTTPCookieProcessor(cj))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With