1.遇到的错误:
raise client_error(req.connection_key, exc) from exc
aiohttp.client_exceptions.ClientProxyConnectionError: Cannot connect to host 119.120.60.115:9999 ssl:default [Connect call failed ('119.120.60.115', 9999)]
2.尝试的解决方法:
分别尝试了以下代码的单独添加和全部添加均无效:
# 作为aiohttp.ClientSession()的参数添加
connector=aiohttp.TCPConnector(limit=64,verify_ssl=False)
trust_env=True
# 使用前独占一行
asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy())
3.软件版本:
Python 3.7.9
aiohttp 3.7.4
错误源代码:
import aiohttp
import asyncio
async def aget(url, proxy, timeout, headers):
async with aiohttp.ClientSession() as session:
async with session.get(url, proxy=proxy, timeout=timeout, headers=headers) as response:
response = await response.text()
print(response)
if __name__ == "__main__":
url = "https://www.ipaddress.com/"
headers = {
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:88.0) Gecko/20100101 Firefox/88.0",
"Accept": "*/*",
"Accept-Encoding": "*",
"Accept-Language": "zh-CN,zh;q=0.8,zh-TW;q=0.7,zh-HK;q=0.5,en-US;q=0.3,en;q=0.2"
}
timeout = 40
# 实际用的无需用户名密码的其他ip和端口
proxy = "http://ip:port"
loop = asyncio.get_event_loop()
loop.run_until_complete(aget(url, proxy, timeout, headers))