def _verify_proxy(self, proxy):
addr = proxy['protocol'] + '://' + proxy['ip'] +':'+proxy['port']
conn = aiohttp.ProxyConnector(proxy=addr)
try:
session = aiohttp.ClientSession(connector=conn)
with aiohttp.Timeout(10):
async with session.get(self.test_url[random.randrange(len(self.test_url))]) as response: # close connection and response, otherwise will tip: Unclosed connection and Unclosed response
try:
assert response.status == 200
redis_sadd(self.redis, self.proxy_key, proxy)
except:
pass
except: #ProxyConnectionError, HttpProxyError and etc?
pass
finally:
session.close() # close session when timeout
评论列表
文章目录