Removing SOCKS 4/5 proxy

This question looks like the opposite:

How to use SOCKS 4/5 proxy with urllib2?

Let's say I use the SOCKS 5 proxy using the method adopted in this question. How can I get it back without a proxy in the same process ?

those. start the process use the proxy .. delete the proxy ...

Maybe there is a better way to use a proxy server so that it is easier to remove it later?

+3
source share
1 answer

Abra cadabra

import socks,socket,urllib2
socks.setdefaultproxy(socks.PROXY_TYPE_SOCKS5, "127.0.0.1", 8080)
temp = socket.socket
socket.socket = socks.socksocket  
print urllib2.urlopen('http://www.google.com').read() // Proxy
socket.socket=temp
print urllib2.urlopen('http://www.google.com').read() // No proxy
+9
source

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


All Articles