@@ -51,39 +51,43 @@ async def check(self, proxy_address: str, timeout: int=None) -> tuple:
51
51
and second one is additional information structure with information like white ip address, country and so on
52
52
"""
53
53
54
+ timeout = timeout if timeout is not None else self .timeout
55
+
56
+ try :
57
+ return await self ._request (proxy_address , timeout )
58
+ except (aiohttp .client_exceptions .ServerDisconnectedError ,
59
+ aiohttp .client_exceptions .ClientHttpProxyError ,
60
+ aiohttp .client_exceptions .ClientProxyConnectionError ,
61
+ aiohttp .client_exceptions .ClientResponseError ,
62
+ aiosocks .errors .SocksError ,
63
+ aiosocks .SocksError ,
64
+ asyncio .TimeoutError ,
65
+ aiohttp .client_exceptions .ClientOSError ,
66
+ ssl .CertificateError ,
67
+ ) as ex :
68
+ message = str (ex )
69
+ if "file" in message :
70
+ print (message )
71
+ # TODO: check for "Too many open files"
72
+
73
+ return False , None
74
+
75
+ async def _request (self , proxy_address , timeout ) -> tuple :
54
76
checker_result = CheckerResult ()
77
+
55
78
if self .url is None :
56
79
raise Exception ()
57
80
58
81
headers = {
59
82
'User-Agent' : async_requests .get_random_user_agent ()
60
83
}
61
-
62
84
conn = ProxyConnector (remote_resolve = True )
63
85
64
- timeout = timeout if timeout is not None else self .timeout
65
-
66
86
with aiohttp .ClientSession (connector = conn , request_class = ProxyClientRequest ) as session :
67
- try :
68
- async with session .request (
69
- self .request_type , self .url , proxy = proxy_address , timeout = timeout , headers = headers ) as \
70
- response :
71
- is_working = await self ._check (response , checker_result )
72
- except (aiohttp .client_exceptions .ServerDisconnectedError ,
73
- aiohttp .client_exceptions .ClientHttpProxyError ,
74
- aiohttp .client_exceptions .ClientProxyConnectionError ,
75
- aiohttp .client_exceptions .ClientResponseError ,
76
- aiosocks .errors .SocksError ,
77
- aiosocks .SocksError ,
78
- asyncio .TimeoutError ,
79
- aiohttp .client_exceptions .ClientOSError ,
80
- ssl .CertificateError ,
81
- ) as ex :
82
- is_working = False
83
- message = str (ex )
84
- if "file" in message :
85
- print (message )
86
- # TODO: check for "Too many open files"
87
+ async with session .request (
88
+ self .request_type , self .url , proxy = proxy_address , timeout = timeout , headers = headers ) as \
89
+ response :
90
+ is_working = await self ._check (response , checker_result )
87
91
88
92
return is_working , checker_result
89
93
0 commit comments