本文介绍了urllib2不使用通过ProxyHandler设置的代理(Fiddler2)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我让Fiddler2收听0.0.0.0:8888.

I have Fiddler2 listening on 0.0.0.0:8888.

try:
    data = ''
    proxy = urllib2.ProxyHandler({'http': '127.0.0.1:8888'})  //also tried {'http': 'http://127.0.0.1:8888/'}
    opener = urllib2.build_opener(proxy)
    urllib2.install_opener(opener)
    req = urllib2.Request('http://www.google.com')
    response = urllib2.urlopen(req)
    the_page = response.read()
        print the_page
except Exception, detail:
    print "Err ", detail

我在Fiddler中看不到GET或对Google的任何请求(但我可以看到其他请求)有没有一种调试方法?似乎python绕过了Fiddler或忽略了代理.

I don't see the GET or any request to google in Fiddler (but I can see other requests)is there a way to debug it? is seems like python bypasses Fiddler or ignores the proxy.

我还配置了WinHTTP以与Fiddler一起使用-

I also configured WinHTTP to work with Fiddler -

C:\Windows\system32>netsh winhttp set proxy 127.0.0.1:8888

Current WinHTTP proxy settings:

    Proxy Server(s) :  127.0.0.1:8888
    Bypass List     :  (none)

是否将其请求到SSL地址有关系吗? (提琴手支持https)

does is matter if the request it to a SSL address? (Fiddler supports https)

谢谢!

推荐答案

也许您可以直接使用打开器,而不必安装它.在8008上打开您的提琴手代理侦听器(我使用的是WebScarab,但它们可能相同),然后完全尝试此代码(也包含不需要的cookie,但请按原样尝试并在以后缩小范围):

Maybe you can work with the opener directly instead of installing it. turn on your fiddler proxy listener on 8008 (i'm using WebScarab, but they're probably the same) then try this code exactly (also has cookies which you don't need, but lets try as-is and narrow it down later):

cj = cookielib.MozillaCookieJar(cookie_filename)
if os.access(cookie_filename, os.F_OK):
    cj.load()
proxy_handler = urllib2.ProxyHandler({'https': 'localhost:8008'})
opener = urllib2.build_opener(
        proxy_handler,
        urllib2.HTTPCookieProcessor(cj)
    )
opener.addheaders = [
        ('User-agent', ('Mozilla/4.0 (compatible; MSIE 6.0; '
                       'Windows NT 5.2; .NET CLR 1.1.4322)'))
    ]
auth = urllib.urlencode({'email':email,'pass':passw})
data = opener.open('https://login.facebook.com/login.php',data=auth)

所以-我做的事情与众不同:直接使用打开器,将端口更改为8008,添加cookie并使用WebScarab.让我知道其中哪一个为您成功了...

so - things i'm doing differently: direct usage of the opener, change the port to 8008, add cookies and use WebScarab. let me know which one of these did the trick for you...

这篇关于urllib2不使用通过ProxyHandler设置的代理(Fiddler2)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-04 15:48