HTTP错误502:父代理无法访问

时间:2016-12-14 05:55:12

标签: python-3.x https proxy httprequest urllib

我已经使用CNTLM完成了代理设置,并且还有一个脚本(google.py)来检查代理设置是否正常

import urllib.request
proxy_support = urllib.request.ProxyHandler({"http":"http://localhost:3128"})
opener = urllib.request.build_opener(proxy_support)
urllib.request.install_opener(opener)
html = urllib.request.urlopen("http://www.google.com").read()
print(html)

当我运行脚本时,我收到了以下错误

C:\Users\asj5cob\Desktop>py -3.4 google.py
Traceback (most recent call last):
  File "google.py", line 5, in <module>
    html = urllib.request.urlopen("http://www.google.com").read()
  File "C:\Python34\lib\urllib\request.py", line 161, in urlopen
    return opener.open(url, data, timeout)
  File "C:\Python34\lib\urllib\request.py", line 470, in open
    response = meth(req, response)
  File "C:\Python34\lib\urllib\request.py", line 580, in http_response
    'http', request, response, code, msg, hdrs)
  File "C:\Python34\lib\urllib\request.py", line 508, in error
    return self._call_chain(*args)
  File "C:\Python34\lib\urllib\request.py", line 442, in _call_chain
    result = func(*args)
  File "C:\Python34\lib\urllib\request.py", line 588, in http_error_default
    raise HTTPError(req.full_url, code, msg, hdrs, fp)
 urllib.error.HTTPError: HTTP Error 502: Parent proxy unreacheable

1 个答案:

答案 0 :(得分:0)

您是否通过在管理员cmd窗口中执行来启动CNTLM?

net start cntlm