requests如何不使用系统代理

1. 指定域名不使用代理

import os
import requests
 
os.environ['NO_PROXY'] = 'stackoverflow.com'
response = requests.get('http://www.stackoverflow.com')

  

2. 设置代理为None

import requests
 
proxies = {
  "http": None,
  "https": None,
}
 
requests.get("http://example.org", proxies=proxies)

  

3. 设置trust_env = False

import requests
 
session = requests.Session()
session.trust_env = False
 
response = session.get('http://www.stackoverflow.com')

  

posted on 2023-04-18 09:05  帅胡  阅读(981)  评论(1编辑  收藏  举报

导航