2007年04月18日 星期三 10:53
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
Zeuux © 2025
京ICP备05028076号