requests中的代理设置

requests模块为常用的Python http请求的模块。

如果需要使用代理,可以这样设置:

import requests
proxies = {
  'http': 'http://10.10.1.10:3128',
  'https': 'http://10.10.1.10:1080',
}
requests.get('http://example.org', proxies=proxies)

但是有一点,如果没有在代码中指定使用代理,但是在Windows的IE中设置了代理服务器,则requests还是会使用代理。(被坑过,导致响应很慢)

如果在IE中设置了代理,但是在脚本中不需要使用代理,可以这样:

proxies = {'http': None, 'https': None}
s.get('http://10.114.19.53:8080/job/SOP_Replay/', proxies=proxies)

这样的话,就可以确保requests不使用系统代理,直连服务器了。

你可能感兴趣的:(requests中的代理设置)