aiohttp,在 GET 上引发错误,无法向 https 网站发送 GET 请求
aiohttp, raising an error on GET, can't send GET request to https website
我有发送 GET 请求的代码部分:
proxy_auth = aiohttp.BasicAuth('proxy-username', 'proxy-password')
async with session.get('https://google.com', headers=headers, proxy='http://proxy_url.com', proxy_auth=proxy_auth) as response:
html = await response.text()
问题是当我尝试获取 https
网站时 returns 这个异常:
ClientConnectorError: Cannot connect to host google.com:443 ssl:default [The parameter is incorrect]
只有https
提供的网站才会抛出这个异常,http
没有异常。
代理是 https
但 aiohttp 只接受 http
代理,但我知道有一些技巧可以让它工作。
我找到了解决该问题的方法。这是因为 aiohttp
库本身,所以我们需要将 Event Policy Loop
更改为 asyncio.WindowsSelectorEventLoopPolicy()
像这样:
import asyncio
asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy())
我有发送 GET 请求的代码部分:
proxy_auth = aiohttp.BasicAuth('proxy-username', 'proxy-password')
async with session.get('https://google.com', headers=headers, proxy='http://proxy_url.com', proxy_auth=proxy_auth) as response:
html = await response.text()
问题是当我尝试获取 https
网站时 returns 这个异常:
ClientConnectorError: Cannot connect to host google.com:443 ssl:default [The parameter is incorrect]
只有https
提供的网站才会抛出这个异常,http
没有异常。
代理是 https
但 aiohttp 只接受 http
代理,但我知道有一些技巧可以让它工作。
我找到了解决该问题的方法。这是因为 aiohttp
库本身,所以我们需要将 Event Policy Loop
更改为 asyncio.WindowsSelectorEventLoopPolicy()
像这样:
import asyncio
asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy())