And using cookies and proxies in Python with urllib2

I am using urllib2 to interact with the web server. For a specific problem, I have to solve, I need to tunnel traffic through a proxy. I managed to do this using urllib2 'ProxyHandler'.

I also need to accept and send cookies. I managed to do this with urllib2 'cookielib.LWPCookieJar ()'.

The problem is that although they work individually, they do not work β€œtogether.” The last constructor that I add with "urllib2.install_opener (opener)" is the one that will work.

Is it possible to have two active "openers"? Or another way to solve this problem?

+6
source share
1 answer

Combine the proxy handler and the cookie processor in one opener:

cj = cookielib.CookieJar() opener = build_opener(ProxyHandler({'http': 'ip:port'}), HTTPCookieProcessor(cj)) 
+10
source

Source: https://habr.com/ru/post/908040/


All Articles