600字范文,内容丰富有趣,生活中的好帮手!
600字范文 > python 爬虫代理_python 爬虫 使用代理 的问题

python 爬虫代理_python 爬虫 使用代理 的问题

时间:2024-06-19 07:03:34

相关推荐

python 爬虫代理_python 爬虫 使用代理 的问题

刚刚在使用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('/')

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('/')

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. )

请问这是什么原因造成的呀,可有什么解决建议啊,谢谢大家了

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。