aiohttp, raising an error on GET, can't send GET request to https website

Viewed 176

I have this code part that sends GET request:

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()

The problem is when I'm trying to GET https website it returns this exception:

ClientConnectorError: Cannot connect to host google.com:443 ssl:default [The parameter is incorrect]

This exception is thrown only when the website is provided by https, with http there's no exceptions. The proxy is https but aiohttp only accepts http proxy, but I know there's some tricks to get it to work.

1 Answers

I found a solution for that problem. It happens because of the aiohttp library itself so we need to change the Event Policy Loop to asyncio.WindowsSelectorEventLoopPolicy()

Like that:

import asyncio
asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy())
Related