刚刚在使用Python写爬虫,但是由于我在公司没有上网权限,所以借别人的账号用(opera 浏览器代理 可有上网),我将代理信息写在python脚本里面但是出现了下面的错误.
代码:
import urllib2
proxy_info = {
'user' : 'xxx' ,
'pass' : 'xxxx' ,
'host' : 'xx.xx.xx.xx' ,
'port' : xx
}
# build a new opener that uses a proxy requiring authorization
proxy_support = urllib2.ProxyHandler({"http" : \
"http://%(user)s:%(pass)s@%(host)s:%(port)d" % proxy_info})
opener = urllib2.build_opener(proxy_support, urllib2.HTTPHandler)
# install it
urllib2.install_opener(opener)
# use it
f = urllib2.urlopen('http://www.baidu.com/')
print f.headers
print f.read()
错误:
Traceback (most recent call last):
File "D:\software\eclipse\workspace\pythonproject\dev\spider\ProxyHandler.py", line 19, in
f = urllib2.urlopen('http://www.baidu.com/')
File "C:\Python27\lib\urllib2.py", line 126, in urlopen
return _opener.open(url, data, timeout)
File "C:\Python27\lib\urllib2.py", line 398, in open
response = meth(req, response)
File "C:\Python27\lib\urllib2.py", line 511, in http_response
'http', request, response, code, msg, hdrs)
File "C:\Python27\lib\urllib2.py", line 436, in error
return self._call_chain(*args)
File "C:\Python27\lib\urllib2.py", line 370, in _call_chain
result = func(*args)
File "C:\Python27\lib\urllib2.py", line 519, in http_error_default
raise HTTPError(req.get_full_url(), code, msg, hdrs, fp)
urllib2.HTTPError: HTTP Error 407: Proxy Authentication Required
( Forefront TMG requires authorization to fulfill the request.
Access to the Web Proxy filter is denied. )
urllib2.HTTPError: HTTP Error 407: Proxy Authentication Required ( Forefront TMG requires authorization to fulfill the request. Access to the Web Proxy filter is denied. )
请问这是什么原因造成的呀,可有什么解决建议啊,谢谢大家了