您可以将插座设置回
socket.socket
import socks
import socket
import requests
_socket = socket.socket
socks.setdefaultproxy(socks.PROXY_TYPE_SOCKS5, "61.8.75.186", 1080)
# With Socks5
socket.socket = socks.socksocket
url = 'http://ip.3300.ir/'
response = requests.get(url, timeout=10)
print("Set ip: {}".format(response.content))
# Without Socks5
socket.socket = _socket
url = 'http://ip.3300.ir/'
response = requests.get(url, timeout=10)
print("Set ip: {}".format(response.content))
如果您正在使用
requests
&燃气轮机;2.10.0您可以设置
SOCKS proxy
在
proxies
参数
import requests
# With Socks5
proxies = {'http':'socks5://61.8.75.186:1080', 'https':'socks5://61.8.75.186:1080'}
url = 'http://ip.3300.ir/'
response = requests.get(url, timeout=10, proxies=proxies)
print("Set ip: {}".format(response.content))
# Without Socks5
url = 'http://ip.3300.ir/'
response = requests.get(url, timeout=10)
print("Set ip: {}".format(response.content))