sudo vim /etc/privoxy/config
# 添加一行
forward-socks5 / 127.0.0.1:1080 .
def set_proxy():
import os
os.environ["https_proxy"] = "http://127.0.0.1:8118"
os.environ["HTTPS_PROXY"] = "http://127.0.0.1:8118"
os.environ["http_proxy"] = "http://127.0.0.1:8118"
os.environ["HTTP_PROXY"] = "http://127.0.0.1:8118"
if __name__ == '__main__':
import requests
try:
print(requests.get("https://www.google.com").status_code) # raise Exception
except Exception as e:
print(e)
set_proxy()
print(requests.get("https://www.google.com").status_code) # 200