2011-11-20 7 views
2

request.meta [ 'proxy']를 사용하여 http 프록시를 설정할 수 있지만 프록시 인증은 어떻게합니까? 둘러보고에서Scream HTTP 프록시 인증

request.meta['proxy'] = 'http://user:[email protected]:2222' 

, 내가 request.headers [ '프록시 인증을'] 보내야 할 수도 있지만, 어떤 형식 나는 그것을 보내 않습니다

이 사용자를 지정하고 전달하는 작동하지 않는 이유는 무엇입니까?

답변

6

사용자 이름과 암호를 base64로 양식으로 인코딩 된 "사용자 이름 : 암호"

import base64 

# Set the location of the proxy 
proxy_string = choice(self._get_proxies_from_file('proxies.txt')) # user:[email protected]:port 
proxy_items = proxy_string.split('@') 
request.meta['proxy'] = "http://%s" % proxy_items[1] 

# setup basic authentication for the proxy 
user_pass=base64.encodestring(proxy_items[0]) 
request.headers['Proxy-Authorization'] = 'Basic ' + user_pass