0

我正在尝试使用身份验证代理向 https 网站发出请求,但我收到以下错误。正如他们在 aiohttp 文档中提到的那样,没有 https 代理支持,所以我想知道这个问题是否有任何解决方案。这也是我的代码。

async def get_site(https_url, proxy):
async with aiohttp.ClientSession() as session:
    async with session.get(https_url,
                           proxy=proxy) as resp:
        text = await resp.text()
        print(text)

loop = asyncio.get_event_loop()
loop.run_until_complete(get_site("https://www.python.org/", "http://user:passw@proxy_url:port"))
loop.run_until_complete(asyncio.sleep(0))
loop.close()

这就是我得到的错误:

Traceback (most recent call last):
  File "C:\Users\Adam\Anaconda3\envs\test\lib\site-packages\aiohttp\connector.py", line 936, in _wrap_create_connection
    return await self._loop.create_connection(*args, **kwargs)  # type: ignore  # noqa
  File "C:\Users\Adam\Anaconda3\envs\test\lib\asyncio\base_events.py", line 1050, in create_connection
    transport, protocol = await self._create_connection_transport(
  File "C:\Users\Adam\Anaconda3\envs\test\lib\asyncio\base_events.py", line 1080, in _create_connection_transport
    await waiter
  File "C:\Users\Adam\Anaconda3\envs\test\lib\asyncio\proactor_events.py", line 395, in _loop_writing
    self._write_fut = self._loop._proactor.send(self._sock, data)
  File "C:\Users\Adam\Anaconda3\envs\test\lib\asyncio\windows_events.py", line 525, in send
    self._register_with_iocp(conn)
  File "C:\Users\Adam\Anaconda3\envs\test\lib\asyncio\windows_events.py", line 714, in _register_with_iocp
    _overlapped.CreateIoCompletionPort(obj.fileno(), self._iocp, 0, 0)
OSError: [WinError 87] The parameter is incorrect

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "C:/Users/Adam/Desktop/test/test.py", line 22, in <module>
    loop.run_until_complete(get_site("https://www.python.org/", "proxy_here"))
  File "C:\Users\Adam\Anaconda3\envs\test\lib\asyncio\base_events.py", line 616, in run_until_complete
    return future.result()
  File "C:/Users/Adam/Desktop/test/test.py", line 15, in waht
    async with session.get("https://www.python.org/",
  File "C:\Users\Adam\Anaconda3\envs\test\lib\site-packages\aiohttp\client.py", line 1012, in __aenter__
    self._resp = await self._coro
  File "C:\Users\Adam\Anaconda3\envs\test\lib\site-packages\aiohttp\client.py", line 480, in _request
    conn = await self._connector.connect(
  File "C:\Users\Adam\Anaconda3\envs\test\lib\site-packages\aiohttp\connector.py", line 523, in connect
    proto = await self._create_connection(req, traces, timeout)
  File "C:\Users\Adam\Anaconda3\envs\test\lib\site-packages\aiohttp\connector.py", line 855, in _create_connection
    _, proto = await self._create_proxy_connection(
  File "C:\Users\Adam\Anaconda3\envs\test\lib\site-packages\aiohttp\connector.py", line 1093, in _create_proxy_connection
    transport, proto = await self._wrap_create_connection(
  File "C:\Users\Adam\Anaconda3\envs\test\lib\site-packages\aiohttp\connector.py", line 943, in _wrap_create_connection
    raise client_error(req.connection_key, exc) from exc
aiohttp.client_exceptions.ClientConnectorError: Cannot connect to host www.python.org:443 ssl:None [The parameter is incorrect]

Process finished with exit code 1
4

0 回答 0