2014-03-31 1 views
0

시스템의 기본 프록시를 사용하여 httplib(2)과 httptunnel을 설정하는 방법이 있습니까? 정보와 자격 증명을 제공 할 필요가 없습니다.httplib에서 기본 프록시 서버 사용

나는 urllib2.ProxyHandler을 보았습니다. 그리고 그것은 내가 원하는 모든 것을하는 것처럼 보입니다. 그러나 httplib 대안을 위해 google을 사용한다면 항상 서버와 포트를 제공해야합니다.

class urllib2.ProxyHandler([proxies]) 

Cause requests to go through a proxy. If proxies is given, it must be a dictionary mapping protocol names to URLs of proxies. 
The default is to read the list of proxies from the environment variables <protocol>_proxy. 
If no proxy environment variables are set, then in a Windows environment proxy settings are obtained from the registry’s Internet Settings section, and in a Mac OS X environment proxy information is retrieved from the OS X System Configuration Framework. 
To disable autodetected proxy pass an empty dictionary.` 

답변

1

은 분명히 HTTPLIB 및 urllib2가 다소 상호 교환

remote_addr = {"host": host, "port": port} 

proxy = urllib2.ProxyHandler() 
proxy_opener = urllib2.build_opener(proxy) 
urllib2.install_opener(proxy_opener) 

http_opener = urllib2.build_opener(urllib2.HTTPHandler) 
params = urllib.urlencode({"data": 'some data'}) 
url = "http://{host}:{port}".format(host=remote_addr['host'], port=remote_addr['port']) 
headers = {"Content-Type": "application/x-www-form-urlencoded", "Accept": "text/plain"} 
request = urllib2.Request(url, params, headers) 
request.get_method = lambda: 'PUT' 
url = http_opener.open(request)