i have configured proxy but fiddler can't capture python's network requests

成都七中2002级7班_大家都是天才~ liu.liuwei.wei at gmail.com
Mon Jul 4 19:33:31 CEST 2011


here's my code. I've change the port from 8888 to 1111.

import urllib2
proxy_support = urllib2.ProxyHandler({'http':'http://127.0.0.1:1111'})
opener = urllib2.build_opener(proxy_support, urllib2.HTTPHandler)
urllib2.install_opener(opener)
content = urllib2.urlopen('http://www.google.com').read()
print content

The weird thing is:
1. If I close fiddler, python throws error when running

Traceback (most recent call last):
  File "C:\Users\Micky\test.py", line 5, in <module>
    content = urllib2.urlopen('http://www.google.com').read()
  File "D:\Python27\lib\urllib2.py", line 126, in urlopen
    return _opener.open(url, data, timeout)
  File "D:\Python27\lib\urllib2.py", line 394, in open
    response = self._open(req, data)
  File "D:\Python27\lib\urllib2.py", line 412, in _open
    '_open', req)
  File "D:\Python27\lib\urllib2.py", line 372, in _call_chain
    result = func(*args)
  File "D:\Python27\lib\urllib2.py", line 1199, in http_open
    return self.do_open(httplib.HTTPConnection, req)
  File "D:\Python27\lib\urllib2.py", line 1174, in do_open
    raise URLError(err)
URLError: <urlopen error [Errno 10061] No connection could be made
because the target machine actively refused it>

2. If I open fiddler, everything works great. But I can't see the
traffic in fiddler. And if I change port from 1111 to any other
number, it works find too.

Any clues?



More information about the Python-list mailing list