|
楼主 |
发表于 2020-9-27 12:56:30
|
显示全部楼层
本帖最后由 阿匠 于 2020-9-27 12:59 编辑
我想进一步检测某个代理ip能不能用
代码如下
想问状态码正常是不是等于说代理ip可用?
但是为什么用这个ip去打开网页不行import requests
url='https://www.baidu.com'
headers={'user-agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.102 Safari/537.36 Edg/85.0.564.51'}
proxy={'http':'123.55.101.73:9999'}
response=requests.get(url=url,headers=headers,proxies=proxy)
if response.status_code!=200:
print('bad')
else:
print('good')
r=requests.get(url='http://jandan.net/',headers=headers,proxies=proxy)
html=r.text
print(html)
然后会打印good 然后报错
Traceback (most recent call last):
File "D:\python\lib\site-packages\urllib3\connection.py", line 160, in _new_conn
(self._dns_host, self.port), self.timeout, **extra_kw
File "D:\python\lib\site-packages\urllib3\util\connection.py", line 84, in create_connection
raise err
File "D:\python\lib\site-packages\urllib3\util\connection.py", line 74, in create_connection
sock.connect(sa)
TimeoutError: [WinError 10060] 由于连接方在一段时间后没有正确答复或连接的主机没有反应,连接尝试失败。
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "D:\python\lib\site-packages\urllib3\connectionpool.py", line 677, in urlopen
chunked=chunked,
File "D:\python\lib\site-packages\urllib3\connectionpool.py", line 392, in _make_request
conn.request(method, url, **httplib_request_kw)
File "D:\python\lib\http\client.py", line 1229, in request
self._send_request(method, url, body, headers, encode_chunked)
File "D:\python\lib\http\client.py", line 1275, in _send_request
self.endheaders(body, encode_chunked=encode_chunked)
File "D:\python\lib\http\client.py", line 1224, in endheaders
self._send_output(message_body, encode_chunked=encode_chunked)
File "D:\python\lib\http\client.py", line 1016, in _send_output
self.send(msg)
File "D:\python\lib\http\client.py", line 956, in send
self.connect()
File "D:\python\lib\site-packages\urllib3\connection.py", line 187, in connect
conn = self._new_conn()
File "D:\python\lib\site-packages\urllib3\connection.py", line 172, in _new_conn
self, "Failed to establish a new connection: %s" % e
urllib3.exceptions.NewConnectionError: <urllib3.connection.HTTPConnection object at 0x0000000003B016D8>: Failed to establish a new connection: [WinError 10060] 由于连接方在一段时间后没有正确答复或连接的主机没有反应,连接尝试失败。
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "D:\python\lib\site-packages\requests\adapters.py", line 449, in send
timeout=timeout
File "D:\python\lib\site-packages\urllib3\connectionpool.py", line 727, in urlopen
method, url, error=e, _pool=self, _stacktrace=sys.exc_info()[2]
File "D:\python\lib\site-packages\urllib3\util\retry.py", line 439, in increment
raise MaxRetryError(_pool, url, error or ResponseError(cause))
urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='125.110.69.22', port=9000): Max retries exceeded with url: http://jandan.net/ (Caused by ProxyError('Cannot connect to proxy.', NewConnectionError('<urllib3.connection.HTTPConnection object at 0x0000000003B016D8>: Failed to establish a new connection: [WinError 10060] 由于连接方在一段时间后没有正确答复或连接的主机没有反应,连接尝试失败。')))
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\wmx\Desktop\testip.py", line 16, in <module>
r=requests.get(url='http://jandan.net/',headers=headers,proxies=proxy)
File "D:\python\lib\site-packages\requests\api.py", line 76, in get
return request('get', url, params=params, **kwargs)
File "D:\python\lib\site-packages\requests\api.py", line 61, in request
return session.request(method=method, url=url, **kwargs)
File "D:\python\lib\site-packages\requests\sessions.py", line 530, in request
resp = self.send(prep, **send_kwargs)
File "D:\python\lib\site-packages\requests\sessions.py", line 643, in send
r = adapter.send(request, **kwargs)
File "D:\python\lib\site-packages\requests\adapters.py", line 510, in send
raise ProxyError(e, request=request)
requests.exceptions.ProxyError: HTTPConnectionPool(host='125.110.69.22', port=9000): Max retries exceeded with url: http://jandan.net/ (Caused by ProxyError('Cannot connect to proxy.', NewConnectionError('<urllib3.connection.HTTPConnection object at 0x0000000003B016D8>: Failed to establish a new connection: [WinError 10060] 由于连接方在一段时间后没有正确答复或连接的主机没有反应,连接尝试失败。')))
>>>
================== RESTART: C:\Users\wmx\Desktop\testip.py ==================
good
Traceback (most recent call last):
File "D:\python\lib\site-packages\urllib3\connection.py", line 160, in _new_conn
(self._dns_host, self.port), self.timeout, **extra_kw
File "D:\python\lib\site-packages\urllib3\util\connection.py", line 84, in create_connection
raise err
File "D:\python\lib\site-packages\urllib3\util\connection.py", line 74, in create_connection
sock.connect(sa)
ConnectionRefusedError: [WinError 10061] 由于目标计算机积极拒绝,无法连接。
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "D:\python\lib\site-packages\urllib3\connectionpool.py", line 677, in urlopen
chunked=chunked,
File "D:\python\lib\site-packages\urllib3\connectionpool.py", line 392, in _make_request
conn.request(method, url, **httplib_request_kw)
File "D:\python\lib\http\client.py", line 1229, in request
self._send_request(method, url, body, headers, encode_chunked)
File "D:\python\lib\http\client.py", line 1275, in _send_request
self.endheaders(body, encode_chunked=encode_chunked)
File "D:\python\lib\http\client.py", line 1224, in endheaders
self._send_output(message_body, encode_chunked=encode_chunked)
File "D:\python\lib\http\client.py", line 1016, in _send_output
self.send(msg)
File "D:\python\lib\http\client.py", line 956, in send
self.connect()
File "D:\python\lib\site-packages\urllib3\connection.py", line 187, in connect
conn = self._new_conn()
File "D:\python\lib\site-packages\urllib3\connection.py", line 172, in _new_conn
self, "Failed to establish a new connection: %s" % e
urllib3.exceptions.NewConnectionError: <urllib3.connection.HTTPConnection object at 0x00000000039A1630>: Failed to establish a new connection: [WinError 10061] 由于目标计算机积极拒绝,无法连接。
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "D:\python\lib\site-packages\requests\adapters.py", line 449, in send
timeout=timeout
File "D:\python\lib\site-packages\urllib3\connectionpool.py", line 727, in urlopen
method, url, error=e, _pool=self, _stacktrace=sys.exc_info()[2]
File "D:\python\lib\site-packages\urllib3\util\retry.py", line 439, in increment
raise MaxRetryError(_pool, url, error or ResponseError(cause))
urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='112.111.217.165', port=9999): Max retries exceeded with url: http://jandan.net/ (Caused by ProxyError('Cannot connect to proxy.', NewConnectionError('<urllib3.connection.HTTPConnection object at 0x00000000039A1630>: Failed to establish a new connection: [WinError 10061] 由于目标计算机积极拒绝,无法连接。')))
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\wmx\Desktop\testip.py", line 16, in <module>
r=requests.get(url='http://jandan.net/',headers=headers,proxies=proxy)
File "D:\python\lib\site-packages\requests\api.py", line 76, in get
return request('get', url, params=params, **kwargs)
File "D:\python\lib\site-packages\requests\api.py", line 61, in request
return session.request(method=method, url=url, **kwargs)
File "D:\python\lib\site-packages\requests\sessions.py", line 530, in request
resp = self.send(prep, **send_kwargs)
File "D:\python\lib\site-packages\requests\sessions.py", line 643, in send
r = adapter.send(request, **kwargs)
File "D:\python\lib\site-packages\requests\adapters.py", line 510, in send
raise ProxyError(e, request=request)
requests.exceptions.ProxyError: HTTPConnectionPool(host='112.111.217.165', port=9999): Max retries exceeded with url: http://jandan.net/ (Caused by ProxyError('Cannot connect to proxy.', NewConnectionError('<urllib3.connection.HTTPConnection object at 0x00000000039A1630>: Failed to establish a new connection: [WinError 10061] 由于目标计算机积极拒绝,无法连接。')))
>>>
================== RESTART: C:\Users\wmx\Desktop\testip.py ==================
good
Traceback (most recent call last):
File "D:\python\lib\site-packages\urllib3\connection.py", line 160, in _new_conn
(self._dns_host, self.port), self.timeout, **extra_kw
File "D:\python\lib\site-packages\urllib3\util\connection.py", line 84, in create_connection
raise err
File "D:\python\lib\site-packages\urllib3\util\connection.py", line 74, in create_connection
sock.connect(sa)
ConnectionRefusedError: [WinError 10061] 由于目标计算机积极拒绝,无法连接。
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "D:\python\lib\site-packages\urllib3\connectionpool.py", line 677, in urlopen
chunked=chunked,
File "D:\python\lib\site-packages\urllib3\connectionpool.py", line 392, in _make_request
conn.request(method, url, **httplib_request_kw)
File "D:\python\lib\http\client.py", line 1229, in request
self._send_request(method, url, body, headers, encode_chunked)
File "D:\python\lib\http\client.py", line 1275, in _send_request
self.endheaders(body, encode_chunked=encode_chunked)
File "D:\python\lib\http\client.py", line 1224, in endheaders
self._send_output(message_body, encode_chunked=encode_chunked)
File "D:\python\lib\http\client.py", line 1016, in _send_output
self.send(msg)
File "D:\python\lib\http\client.py", line 956, in send
self.connect()
File "D:\python\lib\site-packages\urllib3\connection.py", line 187, in connect
conn = self._new_conn()
File "D:\python\lib\site-packages\urllib3\connection.py", line 172, in _new_conn
self, "Failed to establish a new connection: %s" % e
urllib3.exceptions.NewConnectionError: <urllib3.connection.HTTPConnection object at 0x0000000003B516D8>: Failed to establish a new connection: [WinError 10061] 由于目标计算机积极拒绝,无法连接。
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "D:\python\lib\site-packages\requests\adapters.py", line 449, in send
timeout=timeout
File "D:\python\lib\site-packages\urllib3\connectionpool.py", line 727, in urlopen
method, url, error=e, _pool=self, _stacktrace=sys.exc_info()[2]
File "D:\python\lib\site-packages\urllib3\util\retry.py", line 439, in increment
raise MaxRetryError(_pool, url, error or ResponseError(cause))
urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='112.111.217.165', port=9999): Max retries exceeded with url: http://jandan.net/ (Caused by ProxyError('Cannot connect to proxy.', NewConnectionError('<urllib3.connection.HTTPConnection object at 0x0000000003B516D8>: Failed to establish a new connection: [WinError 10061] 由于目标计算机积极拒绝,无法连接。')))
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\wmx\Desktop\testip.py", line 16, in <module>
r=requests.get(url='http://jandan.net/',headers=headers,proxies=proxy)
File "D:\python\lib\site-packages\requests\api.py", line 76, in get
return request('get', url, params=params, **kwargs)
File "D:\python\lib\site-packages\requests\api.py", line 61, in request
return session.request(method=method, url=url, **kwargs)
File "D:\python\lib\site-packages\requests\sessions.py", line 530, in request
resp = self.send(prep, **send_kwargs)
File "D:\python\lib\site-packages\requests\sessions.py", line 643, in send
r = adapter.send(request, **kwargs)
File "D:\python\lib\site-packages\requests\adapters.py", line 510, in send
raise ProxyError(e, request=request)
requests.exceptions.ProxyError: HTTPConnectionPool(host='112.111.217.165', port=9999): Max retries exceeded with url: http://jandan.net/ (Caused by ProxyError('Cannot connect to proxy.', NewConnectionError('<urllib3.connection.HTTPConnection object at 0x0000000003B516D8>: Failed to establish a new connection: [WinError 10061] 由于目标计算机积极拒绝,无法连接。')))
>>>
================== RESTART: C:\Users\wmx\Desktop\testip.py ==================
good
Traceback (most recent call last):
File "D:\python\lib\site-packages\urllib3\connection.py", line 160, in _new_conn
(self._dns_host, self.port), self.timeout, **extra_kw
File "D:\python\lib\site-packages\urllib3\util\connection.py", line 84, in create_connection
raise err
File "D:\python\lib\site-packages\urllib3\util\connection.py", line 74, in create_connection
sock.connect(sa)
TimeoutError: [WinError 10060] 由于连接方在一段时间后没有正确答复或连接的主机没有反应,连接尝试失败。
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "D:\python\lib\site-packages\urllib3\connectionpool.py", line 677, in urlopen
chunked=chunked,
File "D:\python\lib\site-packages\urllib3\connectionpool.py", line 392, in _make_request
conn.request(method, url, **httplib_request_kw)
File "D:\python\lib\http\client.py", line 1229, in request
self._send_request(method, url, body, headers, encode_chunked)
File "D:\python\lib\http\client.py", line 1275, in _send_request
self.endheaders(body, encode_chunked=encode_chunked)
File "D:\python\lib\http\client.py", line 1224, in endheaders
self._send_output(message_body, encode_chunked=encode_chunked)
File "D:\python\lib\http\client.py", line 1016, in _send_output
self.send(msg)
File "D:\python\lib\http\client.py", line 956, in send
self.connect()
File "D:\python\lib\site-packages\urllib3\connection.py", line 187, in connect
conn = self._new_conn()
File "D:\python\lib\site-packages\urllib3\connection.py", line 172, in _new_conn
self, "Failed to establish a new connection: %s" % e
urllib3.exceptions.NewConnectionError: <urllib3.connection.HTTPConnection object at 0x0000000003A414A8>: Failed to establish a new connection: [WinError 10060] 由于连接方在一段时间后没有正确答复或连接的主机没有反应,连接尝试失败。
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "D:\python\lib\site-packages\requests\adapters.py", line 449, in send
timeout=timeout
File "D:\python\lib\site-packages\urllib3\connectionpool.py", line 727, in urlopen
method, url, error=e, _pool=self, _stacktrace=sys.exc_info()[2]
File "D:\python\lib\site-packages\urllib3\util\retry.py", line 439, in increment
raise MaxRetryError(_pool, url, error or ResponseError(cause))
urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='123.55.101.73', port=9999): Max retries exceeded with url: http://jandan.net/ (Caused by ProxyError('Cannot connect to proxy.', NewConnectionError('<urllib3.connection.HTTPConnection object at 0x0000000003A414A8>: Failed to establish a new connection: [WinError 10060] 由于连接方在一段时间后没有正确答复或连接的主机没有反应,连接尝试失败。')))
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\wmx\Desktop\testip.py", line 16, in <module>
r=requests.get(url='http://jandan.net/',headers=headers,proxies=proxy)
File "D:\python\lib\site-packages\requests\api.py", line 76, in get
return request('get', url, params=params, **kwargs)
File "D:\python\lib\site-packages\requests\api.py", line 61, in request
return session.request(method=method, url=url, **kwargs)
File "D:\python\lib\site-packages\requests\sessions.py", line 530, in request
resp = self.send(prep, **send_kwargs)
File "D:\python\lib\site-packages\requests\sessions.py", line 643, in send
r = adapter.send(request, **kwargs)
File "D:\python\lib\site-packages\requests\adapters.py", line 510, in send
raise ProxyError(e, request=request)
requests.exceptions.ProxyError: HTTPConnectionPool(host='123.55.101.73', port=9999): Max retries exceeded with url: http://jandan.net/ (Caused by ProxyError('Cannot connect to proxy.', NewConnectionError('<urllib3.connection.HTTPConnection object at 0x0000000003A414A8>: Failed to establish a new connection: [WinError 10060] 由于连接方在一段时间后没有正确答复或连接的主机没有反应,连接尝试失败。')))
想问状态码正常是不是等于说代理ip可用?
但是为什么用这个ip去打开网页不行 |
|