用nginx做一个http proxy. `resolver*`这个字段是必要的。
server { resolver 8.8.8.8; resolver_timeout 5s; listen 0.0.0.0:64441; location / { proxy_pass $scheme://$http_host$request_uri; proxy_set_header Host $http_host; proxy_connect_timeout 5; } }
然后来测试一下
In [10]: import requests In [11]: r = requests.get('http://www.baidu.com', **{'proxies': {'http': 'http://127.0.0.1:64441'}}) In [12]: r Out[12]: <Response [200]>