Skip to content

ws_connect doesn't follow proxy from environment #4648

Closed
@lookis

Description

🐞 Describe the bug

I have set both http_proxy and https_proxy, with trust_env=True when create ClientSession,
everything is ok when get or post with this session, but for the ws_connect, It doesn't run with proxy.

💡 To Reproduce

background: I cann't visit wss://stream.binance.com:9443/ws under my network but it's ok with proxy

  1. prepare a proxy at port 1086
  2. http_proxy="http://127.0.0.1:1086"
  3. https_proxy="https://127.0.0.1:1086"
import asyncio
import aiohttp
async def main():
    async with aiohttp.ClientSession(trust_env=True) as client:
        await client.ws_connect('wss://stream.binance.com:9443/ws')
        print('ok')

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

and it block forever (with a tcp handshake timeout exception)

💡 Expected behavior

just connect with proxy

📋 Logs/tracebacks

📋 Your version of the Python

$ python --version
Python 3.7.6

📋 Your version of the aiohttp/yarl/multidict distributions

$ python -m pip show aiohttp
Version: 3.6.2
$ python -m pip show multidict
Version: 4.7.5
$ python -m pip show yarl
Version: 1.1.0

📋 Additional context

if scheme == url.scheme:

scheme of websocket is ws or wss, url.scheme will always be http or https and ignore any other proxy here
if k in ('http', 'https')}

but it's ok for ws/wss to use http proxy

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions