Skip to content

Problems when using proxy under Windows #4536

@libra146

Description

@libra146

Long story short

I get an error when running the following code under Python 3.8.1 and aiohttp3.6.2 under Windows

import aiohttp
import asyncio


async def main():
    async with aiohttp.ClientSession() as session:
        async with session.get('https://python.org', proxy='http://127.0.0.1:8888') as response:
            print("Status:", response.status)
            print("Content-type:", response.headers['content-type'])

            html = await response.text()
            print("Body:", html[:15], "...")


loop = asyncio.get_event_loop()
loop.run_until_complete(main())

Expected behaviour

Status: 200
Content-type: text/html; charset=utf-8
Body: <!doctype html> ...

Actual behaviour

Traceback (most recent call last):
  File "C:\Python38\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:\Python38\lib\asyncio\base_events.py", line 1046, in create_connection

    transport, protocol = await self._create_connection_transport(
  File "C:\Python38\lib\asyncio\base_events.py", line 1076, in _create_connectio
n_transport
    await waiter
  File "C:\Python38\lib\asyncio\proactor_events.py", line 395, in _loop_writing
    self._write_fut = self._loop._proactor.send(self._sock, data)
  File "C:\Python38\lib\asyncio\windows_events.py", line 525, in send
    self._register_with_iocp(conn)
  File "C:\Python38\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 "test5.py", line 16, in <module>
    loop.run_until_complete(main())
  File "C:\Python38\lib\asyncio\base_events.py", line 612, in run_until_complete

    return future.result()
  File "test5.py", line 7, in main
    async with session.get('https://python.org', proxy='http://192.168.233.1:108
8') as response:
  File "C:\Python38\lib\site-packages\aiohttp\client.py", line 1012, in __aenter
__
    self._resp = await self._coro
  File "C:\Python38\lib\site-packages\aiohttp\client.py", line 480, in _request
    conn = await self._connector.connect(
  File "C:\Python38\lib\site-packages\aiohttp\connector.py", line 523, in connec
t
    proto = await self._create_connection(req, traces, timeout)
  File "C:\Python38\lib\site-packages\aiohttp\connector.py", line 855, in _creat
e_connection
    _, proto = await self._create_proxy_connection(
  File "C:\Python38\lib\site-packages\aiohttp\connector.py", line 1093, in _crea
te_proxy_connection
    transport, proto = await self._wrap_create_connection(
  File "C:\Python38\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 python.or
g:443 ssl:default [The parameter is incorrect]

Steps to reproduce

Run the above code

Your environment

OS: windows7
proxy: v2ray
aiohttp: 3.6.2(client)
python: 3.8.1

When I remove the proxy parameter, it works fine

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions