Skip to content

Commit c2924c5

Browse files
committed
fix
1 parent 8569e03 commit c2924c5

File tree

2 files changed

+34
-21
lines changed

2 files changed

+34
-21
lines changed

processor.py

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -77,18 +77,18 @@ async def consumer(self):
7777
while True:
7878
await asyncio.sleep(0.1)
7979
i = 0
80-
async with aiohttp.ClientSession(
81-
connector=ProxyConnector(remote_resolve=False),
82-
request_class=ProxyClientRequest
83-
) as aiohttp_proxy_check_session:
84-
while not self.queue.empty() and i <= settings.CONCURRENT_TASKS_COUNT:
85-
proxy_data = self.queue.get_nowait()
86-
tasks.append(self.process_proxy(*proxy_data, aiohttp_proxy_check_session))
87-
self.queue.task_done()
88-
89-
if tasks:
90-
await asyncio.wait(tasks)
91-
tasks.clear()
80+
# async with aiohttp.ClientSession(
81+
# connector=ProxyConnector(remote_resolve=False),
82+
# request_class=ProxyClientRequest
83+
# ) as aiohttp_proxy_check_session:
84+
while not self.queue.empty() and i <= settings.CONCURRENT_TASKS_COUNT:
85+
proxy_data = self.queue.get_nowait()
86+
tasks.append(self.process_proxy(*proxy_data))
87+
self.queue.task_done()
88+
89+
if tasks:
90+
await asyncio.wait(tasks)
91+
tasks.clear()
9292

9393
async def producer(self):
9494
while True:
@@ -200,7 +200,7 @@ async def process_raw_proxies(self, proxies, collector_id):
200200
))
201201

202202
async def process_proxy(self, raw_protocol: int, auth_data: str, domain: str, port: int, collector_id: int,
203-
aiohttp_proxy_check_session):
203+
aiohttp_proxy_check_session=None):
204204
self.logger.debug("start processing proxy {}://{}@{}:{} with collector id {}".format(
205205
raw_protocol, auth_data, domain, port, collector_id))
206206

@@ -253,6 +253,8 @@ async def process_proxy(self, raw_protocol: int, auth_data: str, domain: str, po
253253
session.rollback()
254254
self.logger.error("Error during processing proxy")
255255
self.logger.exception(ex)
256+
print("Exception proxy_url = {}".format(proxy_url))
257+
exit(1)
256258

257259
@staticmethod
258260
def create_or_update_proxy(raw_protocol: Proxy.PROTOCOLS, auth_data, domain, port,

proxy_utils.py

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import traceback
22

3+
import sys
4+
35
from proxy_py import settings
46
import async_requests
57

@@ -9,18 +11,21 @@
911
import aiosocks
1012
import os
1113

14+
from aiosocks.connector import ProxyConnector, ProxyClientRequest
15+
1216

1317
# TODO: add multiple checks with several sites
14-
async def check_proxy(proxy_url: str, session):
18+
async def check_proxy(proxy_url: str, session=None):
1519
try:
1620
res = await _request(
1721
'get',
1822
'https://pikagraphs.d3d.info/OK/',
23+
# 'https://wtfismyip.com/text',
1924
proxy_url,
2025
settings.PROXY_CHECKING_TIMEOUT,
2126
session
2227
)
23-
28+
2429
if res.status == 200 and res.text == "OK":
2530
return True
2631
except (aiohttp.client_exceptions.ServerDisconnectedError,
@@ -35,16 +40,22 @@ async def check_proxy(proxy_url: str, session):
3540
message = str(ex)
3641
if "file" in message:
3742
print(message)
38-
# TODO: check to "Too many open files"
43+
# TODO: check for "Too many open files"
3944
return False
4045

46+
return False
4147

42-
async def _request(method, url, proxy_url, timeout, session : aiohttp.ClientSession):
48+
49+
async def _request(method, url, proxy_url, timeout, session: aiohttp.ClientSession=None):
4350
headers = {
4451
'User-Agent': async_requests.get_random_user_agent()
4552
}
4653

47-
async with session.request(method, url, timeout=timeout, headers=headers, proxy=proxy_url) as response:
48-
status = response.status
49-
text = await response.text()
50-
return async_requests.Response(status, text)
54+
conn = ProxyConnector(remote_resolve=True)
55+
56+
with aiohttp.ClientSession(connector=conn, request_class=ProxyClientRequest) as session:
57+
async with session.request(method, url, proxy=proxy_url, timeout=timeout) as response:
58+
# async with session.request(method, url, timeout=timeout, headers=headers, proxy=proxy_url) as response:
59+
status = response.status
60+
text = await response.text()
61+
return async_requests.Response(status, text)

0 commit comments

Comments
 (0)