|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
- import urllib.request
- url='http://www.ip.cn/'
- proxy_support = urllib.request.ProxyHandler({'https':'60.190.250.120'})
- opener = urllib.request.build_opener(proxy_support)
- opener.addheaders = [('User-Agent','Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.26 Safari/537.36 Core/1.63.6776.400 QQBrowser/10.3.2577.400')]
- urllib.request.install_opener(opener)
- response=urllib.request.urlopen(url)
- html=response.read().decode('utf-8')
- print(html)
复制代码
运行之后显示:
Traceback (most recent call last):
File "E:\Python\lib\urllib\request.py", line 1317, in do_open
encode_chunked=req.has_header('Transfer-encoding'))
File "E:\Python\lib\http\client.py", line 1229, in request
self._send_request(method, url, body, headers, encode_chunked)
File "E:\Python\lib\http\client.py", line 1275, in _send_request
self.endheaders(body, encode_chunked=encode_chunked)
File "E:\Python\lib\http\client.py", line 1224, in endheaders
self._send_output(message_body, encode_chunked=encode_chunked)
File "E:\Python\lib\http\client.py", line 1016, in _send_output
self.send(msg)
File "E:\Python\lib\http\client.py", line 956, in send
self.connect()
File "E:\Python\lib\http\client.py", line 1384, in connect
super().connect()
File "E:\Python\lib\http\client.py", line 928, in connect
(self.host,self.port), self.timeout, self.source_address)
File "E:\Python\lib\socket.py", line 727, in create_connection
raise err
File "E:\Python\lib\socket.py", line 716, in create_connection
sock.connect(sa)
TimeoutError: [WinError 10060] 由于连接方在一段时间后没有正确答复或连接的主机没有反应,连接尝试失败。
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\82539\Desktop\ceshi1.py", line 13, in <module>
response=urllib.request.urlopen(url)
File "E:\Python\lib\urllib\request.py", line 222, in urlopen
return opener.open(url, data, timeout)
File "E:\Python\lib\urllib\request.py", line 531, in open
response = meth(req, response)
File "E:\Python\lib\urllib\request.py", line 641, in http_response
'http', request, response, code, msg, hdrs)
File "E:\Python\lib\urllib\request.py", line 563, in error
result = self._call_chain(*args)
File "E:\Python\lib\urllib\request.py", line 503, in _call_chain
result = func(*args)
File "E:\Python\lib\urllib\request.py", line 755, in http_error_302
return self.parent.open(new, timeout=req.timeout)
File "E:\Python\lib\urllib\request.py", line 525, in open
response = self._open(req, data)
File "E:\Python\lib\urllib\request.py", line 543, in _open
'_open', req)
File "E:\Python\lib\urllib\request.py", line 503, in _call_chain
result = func(*args)
File "E:\Python\lib\urllib\request.py", line 1360, in https_open
context=self._context, check_hostname=self._check_hostname)
File "E:\Python\lib\urllib\request.py", line 1319, in do_open
raise URLError(err)
urllib.error.URLError: <urlopen error [WinError 10060] 由于连接方在一段时间后没有正确答复或连接的主机没有反应,连接尝试失败。>
|
|