Skip to content

Commit 5a3d074

Browse files
committed
some fixes
1 parent d307de9 commit 5a3d074

File tree

3 files changed

+37
-31
lines changed

3 files changed

+37
-31
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,4 @@ migrations
99
alembic.ini
1010
alembic
1111
env/
12+
local_checkers/

checkers/base_checker.py

Lines changed: 27 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -51,39 +51,43 @@ async def check(self, proxy_address: str, timeout: int=None) -> tuple:
5151
and second one is additional information structure with information like white ip address, country and so on
5252
"""
5353

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:
5476
checker_result = CheckerResult()
77+
5578
if self.url is None:
5679
raise Exception()
5780

5881
headers = {
5982
'User-Agent': async_requests.get_random_user_agent()
6083
}
61-
6284
conn = ProxyConnector(remote_resolve=True)
6385

64-
timeout = timeout if timeout is not None else self.timeout
65-
6686
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)
8791

8892
return is_working, checker_result
8993

processor.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -301,17 +301,18 @@ def create_or_update_proxy(raw_protocol: Proxy.PROTOCOLS, auth_data, domain, por
301301
proxy.number_of_bad_checks = 0
302302
proxy.last_check_time = int(time.time())
303303

304-
if additional_info.ipv4 is not None:
305-
proxy.white_ipv4 = additional_info.ipv4
304+
if additional_info is not None:
305+
if additional_info.ipv4 is not None:
306+
proxy.white_ipv4 = additional_info.ipv4
306307

307-
if additional_info.city is not None:
308-
proxy.city = additional_info.city
308+
if additional_info.city is not None:
309+
proxy.city = additional_info.city
309310

310-
if additional_info.region is not None:
311-
proxy.region = additional_info.region
311+
if additional_info.region is not None:
312+
proxy.region = additional_info.region
312313

313-
if additional_info.country_code is not None:
314-
proxy.country_code = additional_info.country_code.strip().lower()
314+
if additional_info.country_code is not None:
315+
proxy.country_code = additional_info.country_code.strip().lower()
315316

316317
checking_time = int(end_checking_time - start_checking_time)
317318
if checking_time > settings.PROXY_CHECKING_TIMEOUT:

0 commit comments

Comments
 (0)