from urllib.parse import urlsplit
import asyncio
+from aiohttp_socks import ProxyConnector
+from python_socks import parse_proxy_url
import aioftp
import aiohttp
import aiohttp.client_exceptions
else:
proxy = None
- error, status, resp_headers, body = asyncio.run(get_http(
+ error, status, resp_headers, body = asyncio.run(_get_http(
url, headers=headers, proxy=proxy,
timeout=self.timeout,
))
return '' # We don't store welcome message yet
-async def get_http(url, headers={}, proxy=None, timeout=60):
+async def _get_http(url, headers={}, proxy=None, timeout=60):
+ connector = None
+ if proxy and proxy.startswith('socks5'):
+ if proxy.startswith('socks5h://'):
+ proxy = proxy.replace('socks5h://', 'socks5://')
+ rdns = True
+ else:
+ rdns = False
+ proxy_type, proxy_host, proxy_port, pusername, ppassword = \
+ parse_proxy_url(proxy)
+ connector = ProxyConnector(
+ proxy_type=proxy_type, host=proxy_host, port=proxy_port,
+ username=pusername, password=ppassword, rdns=rdns,
+ )
+ proxy = None
timeout = aiohttp.ClientTimeout(connect=timeout, total=timeout)
try:
- async with aiohttp.ClientSession(timeout=timeout) as session:
+ async with aiohttp.ClientSession(
+ connector=connector, timeout=timeout
+ ) as session:
async with session.get(
url, headers=headers, proxy=proxy,
allow_redirects=False) as resp:
'Operating System :: OS Independent',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3 :: Only',
- 'Programming Language :: Python :: 3.4',
'Programming Language :: Python :: 3.5',
'Programming Language :: Python :: 3.6',
'Programming Language :: Python :: 3.7',
'Programming Language :: Python :: 3.11',
'Programming Language :: Python :: 3.12',
],
- python_requires='>=3.4',
+ python_requires='>=3.5.3',
install_requires=[
'm_lib.full>=1.0',
],
'html': ['beautifulsoup4', 'lxml'],
'requests': ['requests[socks]'],
'curl': ['pycurl', 'certifi'],
- 'aiohttp': ['aiohttp', 'aioftp'],
+ 'aiohttp': ['aiohttp>=2.3.2', 'aiohttp-socks', 'aioftp'],
},
)