|
楼主 |
发表于 2018-4-30 17:14:08
|
显示全部楼层
File "E:\Python\Python37\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 "G:\PythonCode\lesson55\test\prox_eg.py", line 17, in <module>
response=urllib.request.urlopen(ur1)
File "E:\Python\Python37\lib\urllib\request.py", line 222, in urlopen
return opener.open(url, data, timeout)
File "E:\Python\Python37\lib\urllib\request.py", line 525, in open
response = self._open(req, data)
File "E:\Python\Python37\lib\urllib\request.py", line 543, in _open
'_open', req)
File "E:\Python\Python37\lib\urllib\request.py", line 503, in _call_chain
result = func(*args)
File "E:\Python\Python37\lib\urllib\request.py", line 1345, in http_open
return self.do_open(http.client.HTTPConnection, req)
File "E:\Python\Python37\lib\urllib\request.py", line 1319, in do_open
raise URLError(err)
urllib.error.URLError: <urlopen error [WinError 10060] 由于连接方在一段时间后没有正确答复或连接的主机没有反应,连接尝试失败。>
源码:
import urllib.request
import urllib.parse
ur1='http://www.whatismyip.com.tw'
ur2='http://www.ip138.com/ips1388.asp?ip=36.149.134.186&action=2'
# data={}
# data['ip']='36.149.134.186'
prox_support=urllib.request.ProxyHandler({'http':'171.37.163.74:8123'})#配置代理
opener=urllib.request.build_opener(prox_support)#构造一个代理
urllib.request.install_opener(opener)#安装代理,此时本机的ip已经被伪装成构造的伪代理
# data=urllib.parse.urlencode(data).encode('utf-8')
# header={'User-Agent':'Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.65 Safari/537.36'}
# req=urllib.request.Request(ur1,header)
response=urllib.request.urlopen(ur1)
html=response.read().decode('utf-8')
print(html)
|
|