【发布时间】:2020-09-19 16:19:39
【问题描述】:
我想在我的代码中使用 socks5 代理。如何做到这一点?
我的代码:
from urllib.request import Request, urlopen
url = "https://api.ipify.org/"
request = Request(url)
response = urlopen(request)
print(response.read())
此外,我可以说使用 http/https 代理
我做到了:
request.set_proxy(proxy_address, "http")
之前response = urlopen(url),现在不行了。
编辑
我发现了这样的东西
from urllib.request import Request, urlopen
import socks
import socket
request = Request("https://api.ipify.org/")
socks.set_default_proxy(socks.SOCKS5, IP_ADDR, PORT)
socket.socket = socks.socksocket
response = urlopen(request)
print(response.read())
但它给了我ssl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: self signed certificate in certificate chain
【问题讨论】:
标签: python python-3.x web-scraping urllib socks