|
|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
import urllib.request
url = 'http://www.whatismyip.com'
proxy_support = urllib.request.ProxyHandler({'http':'124.205.155.156:9090'})
opener = urllib.request.build_opener(proxy_support)
urllib.request.install_opener(opener)
response = urllib.request.urlopen(url)
html = response.read().decode('utf-8')
print(html)
运行后
K:\untitled\venv\Scripts\python.exe K:/untitled/proxy.py
Traceback (most recent call last):
File "D:\BIG DATA\Python\lib\urllib\request.py", line 1317, in do_open
encode_chunked=req.has_header('Transfer-encoding'))
File "D:\BIG DATA\Python\lib\http\client.py", line 1229, in request
self._send_request(method, url, body, headers, encode_chunked)
File "D:\BIG DATA\Python\lib\http\client.py", line 1275, in _send_request
self.endheaders(body, encode_chunked=encode_chunked)
File "D:\BIG DATA\Python\lib\http\client.py", line 1224, in endheaders
self._send_output(message_body, encode_chunked=encode_chunked)
File "D:\BIG DATA\Python\lib\http\client.py", line 1016, in _send_output
self.send(msg)
File "D:\BIG DATA\Python\lib\http\client.py", line 956, in send
self.connect()
File "D:\BIG DATA\Python\lib\http\client.py", line 928, in connect
(self.host,self.port), self.timeout, self.source_address)
File "D:\BIG DATA\Python\lib\socket.py", line 727, in create_connection
raise err
File "D:\BIG DATA\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 "K:/untitled/proxy.py", line 14, in <module>
response = urllib.request.urlopen(url)
File "D:\BIG DATA\Python\lib\urllib\request.py", line 222, in urlopen
return opener.open(url, data, timeout)
File "D:\BIG DATA\Python\lib\urllib\request.py", line 525, in open
response = self._open(req, data)
File "D:\BIG DATA\Python\lib\urllib\request.py", line 543, in _open
'_open', req)
File "D:\BIG DATA\Python\lib\urllib\request.py", line 503, in _call_chain
result = func(*args)
File "D:\BIG DATA\Python\lib\urllib\request.py", line 1345, in http_open
return self.do_open(http.client.HTTPConnection, req)
File "D:\BIG DATA\Python\lib\urllib\request.py", line 1319, in do_open
raise URLError(err)
urllib.error.URLError: <urlopen error [WinError 10060] 由于连接方在一段时间后没有正确答复或连接的主机没有反应,连接尝试失败。>
进程已结束,退出代码1
|
|