Python论坛  - 讨论区

标题:[python-chinese] 在urllib2中使用proxy问题

2007年04月18日 星期三 10:53

j hh jhi0796在gmail.com
星期三 四月 18 10:53:11 HKT 2007

    import urllib2
    import httplib
    httplib.HTTPConnection.debuglevel = 1
    proxy_handler = urllib2.ProxyHandler({'http': '
http://proxy.xxx.com:8080'})
    proxy_auth_handler = urllib2.ProxyDigestAuthHandler()
    proxy_auth_handler.add_password('sjsx', 'http://proxy.xxx.com:8080',
'jack', '78923')
  #proxy_auth_handler.add_password('realm', 'host', 'username',
'password')²»ÖªhostÊDz»ÊÇÕâÑùд,»¹ÊÇʹÓñ¾»úµØÖ·,²»¹ýÁ½Õ߶¼Êǵ¼ÖÂÏàͬ´íÎó
    opener = urllib2.build_opener(proxy_handler, proxy_auth_handler)
    urllib2.install_opener(opener)
    text=opener.open('http://www.google.cn').read()
    output=open('output.html','w')
    output.write(text)
    output.close()

errors:
 File "E:\eclipse3.2\eclipse\workspace\pythontest\src\using_urllib2.py",
line 44, in test_urllib2_2
    text=opener.open('http://www.google.cn').read()
  File "C:\Python25\Lib\urllib2.py", line 381, in open
    response = meth(req, response)
  File "C:\Python25\Lib\urllib2.py", line 494, in http_response
    'http', request, response, code, msg, hdrs)
  File "C:\Python25\Lib\urllib2.py", line 419, in error
    return self._call_chain(*args)
  File "C:\Python25\Lib\urllib2.py", line 353, in _call_chain
    result = func(*args)
  File "C:\Python25\Lib\urllib2.py", line 502, in http_error_default
    raise HTTPError(req.get_full_url(), code, msg, hdrs, fp)
urllib2.HTTPError: HTTP Error 407: Proxy Authentication Required ( The ISA
Server requires authorization to fulfill the request. Access to the Web
Proxy filter is denied.  )

ͬÑùÔÚQQÖÐÏàͬµÄÉèÖÃ,È´Äܹ»Á¬½Ó,Ϊʲôpython²»ÐÐÄØ?
-------------- 下一部分 --------------
Ò»¸öHTML¸½¼þ±»ÒƳý...
URL: http://python.cn/pipermail/python-chinese/attachments/20070418/f914db8e/attachment.html 

[导入自Mailman归档:http://www.zeuux.org/pipermail/zeuux-python]

如下红色区域有误,请重新填写。

    你的回复:

    请 登录 后回复。还没有在Zeuux哲思注册吗?现在 注册 !

    Zeuux © 2025

    京ICP备05028076号