|
|
10鱼币
本帖最后由 光宇 于 2017-4-14 16:32 编辑
代码都是复制小甲鱼的,代理也换了,在百度找了十几个代理d网站,几十个代理都出问题了。
代码详细
- import urllib.request
- url = 'http://www.whatismyip.com.tw'
- proxy_support = urllib.request.ProxyHandler({'http':'115.200.171.145:8123'})
- opener = urllib.request.build_opener(proxy_support)
- urllib.request.install_opener(opener)
- response = urllib.request.urlopen(url)
- html = reponse.read().decode('utf-8')
- print(html)
复制代码
运行结果
情况1:无响应
- Traceback (most recent call last):
- File "C:\Users\Administrator\Desktop\python\proxy_eg.py", line 13, in <module>
- html = reponse.read().decode('utf-8')
- NameError: name 'reponse' is not defined
复制代码
情况2:请求超时
- Traceback (most recent call last):
- File "C:\Users\Administrator\Desktop\python\proxy_eg.py", line 11, in <module>
- response = urllib.request.urlopen(url)
- File "C:\Python33\lib\urllib\request.py", line 156, in urlopen
- return opener.open(url, data, timeout)
- File "C:\Python33\lib\urllib\request.py", line 475, in open
- response = meth(req, response)
- File "C:\Python33\lib\urllib\request.py", line 587, in http_response
- 'http', request, response, code, msg, hdrs)
- File "C:\Python33\lib\urllib\request.py", line 513, in error
- return self._call_chain(*args)
- File "C:\Python33\lib\urllib\request.py", line 447, in _call_chain
- result = func(*args)
- File "C:\Python33\lib\urllib\request.py", line 595, in http_error_default
- raise HTTPError(req.full_url, code, msg, hdrs, fp)
- urllib.error.HTTPError: HTTP Error 504: Gateway Timeout
复制代码
情况3:主机无反应,链接失败
- >>>
- Traceback (most recent call last):
- File "C:\Python33\lib\urllib\request.py", line 1248, in do_open
- h.request(req.get_method(), req.selector, req.data, headers)
- File "C:\Python33\lib\http\client.py", line 1061, in request
- self._send_request(method, url, body, headers)
- File "C:\Python33\lib\http\client.py", line 1099, in _send_request
- self.endheaders(body)
- File "C:\Python33\lib\http\client.py", line 1057, in endheaders
- self._send_output(message_body)
- File "C:\Python33\lib\http\client.py", line 902, in _send_output
- self.send(msg)
- File "C:\Python33\lib\http\client.py", line 840, in send
- self.connect()
- File "C:\Python33\lib\http\client.py", line 818, in connect
- self.timeout, self.source_address)
- File "C:\Python33\lib\socket.py", line 435, in create_connection
- raise err
- File "C:\Python33\lib\socket.py", line 426, 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\Administrator\Desktop\python\proxy_eg.py", line 11, in <module>
- response = urllib.request.urlopen(url)
- File "C:\Python33\lib\urllib\request.py", line 156, in urlopen
- return opener.open(url, data, timeout)
- File "C:\Python33\lib\urllib\request.py", line 469, in open
- response = self._open(req, data)
- File "C:\Python33\lib\urllib\request.py", line 487, in _open
- '_open', req)
- File "C:\Python33\lib\urllib\request.py", line 447, in _call_chain
- result = func(*args)
- File "C:\Python33\lib\urllib\request.py", line 1268, in http_open
- return self.do_open(http.client.HTTPConnection, req)
- File "C:\Python33\lib\urllib\request.py", line 1251, in do_open
- raise URLError(err)
- urllib.error.URLError: <urlopen error [WinError 10060] 由于连接方在一段时间后没有正确答复或连接的主机没有反应,连接尝试失败。>
复制代码
情况4:软件中止了
- >>>
- Traceback (most recent call last):
- File "C:\\Users\\Administrator\\Desktop\\python\\proxy_eg.py", line 11, in <module>
- response = urllib.request.urlopen(url)
- File "C:\\Python33\\lib\\urllib\\request.py", line 156, in urlopen
- return opener.open(url, data, timeout)
- File "C:\\Python33\\lib\\urllib\\request.py", line 469, in open
- response = self._open(req, data)
- File "C:\\Python33\\lib\\urllib\\request.py", line 487, in _open
- '_open', req)
- File "C:\\Python33\\lib\\urllib\\request.py", line 447, in _call_chain
- result = func(*args)
- File "C:\\Python33\\lib\\urllib\\request.py", line 1268, in http_open
- return self.do_open(http.client.HTTPConnection, req)
- File "C:\\Python33\\lib\\urllib\\request.py", line 1253, in do_open
- r = h.getresponse()
- File "C:\\Python33\\lib\\http\\client.py", line 1143, in getresponse
- response.begin()
- File "C:\\Python33\\lib\\http\\client.py", line 354, in begin
- version, status, reason = self._read_status()
- File "C:\\Python33\\lib\\http\\client.py", line 316, in _read_status
- line = str(self.fp.readline(_MAXLINE + 1), "iso-8859-1")
- File "C:\\Python33\\lib\\socket.py", line 297, in readinto
- return self._sock.recv_into(b)
- ConnectionAbortedError: [WinError 10053] 你的主机中的软件中止了一个已建立的连接。
复制代码
免费IP大部分都是无效,小部分是偶尔有效,总之,免费代理IP根本不靠谱
然后,你的第一个报错并不是无响应,而是你打错一个变量名NameError: name 'reponse' is not defined
你把response打错了
|
最佳答案
查看完整内容
免费IP大部分都是无效,小部分是偶尔有效,总之,免费代理IP根本不靠谱
然后,你的第一个报错并不是无响应,而是你打错一个变量名NameError: name 'reponse' is not defined
你把response打错了
|