You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用HTTPS_PROXY与trust_env=True时aiohttp报AttributeError异常

aiohttp 3.8 环境变量代理连接报错:AttributeError: 'NoneType' object has no attribute 'get_extra_info'
  • 环境与操作:
    • 使用aiohttp 3.8版本
    • 创建ClientSession时设置trust_env=True,通过环境变量指定代理,执行命令:https_proxy=http://localhost:9090 python3 cli.py
  • 触发错误:出现AttributeError: 'NoneType' object has no attribute 'get_extra_info',完整报错栈如下:
File "/opt/homebrew/lib/python3.11/site-packages/aiohttp/client.py", line 1141, in __aenter__
    self._resp = await self._coro
                ^^^^^^^^^^^^^^^^
  File "/opt/homebrew/lib/python3.11/site-packages/aiohttp/client.py", line 536, in _request
    conn = await self._connector.connect(
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/lib/python3.11/site-packages/aiohttp/connector.py", line 540, in connect
    proto = await self._create_connection(req, traces, timeout)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/lib/python3.11/site-packages/aiohttp/connector.py", line 899, in _create_connection
    _, proto = await self._create_proxy_connection(req, traces, timeout)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/lib/python3.11/site-packages/aiohttp/connector.py", line 1325, in _create_proxy_connection
    return await self._start_tls_connection(
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/lib/python3.11/site-packages/aiohttp/connector.py", line 1124, in _start_tls_connection
    tls_proto.connection_made(
  File "/opt/homebrew/lib/python3.11/site-packages/aiohttp/base_protocol.py", line 62, in connection_made
    tcp_nodelay(tr, True)
  File "/opt/homebrew/lib/python3.11/site-packages/aiohttp/tcp_helpers.py", line 25, in tcp_nodelay
    sock = transport.get_extra_info("socket")
          ^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'get_extra_info'
ERROR:asyncio:Unclosed client session
client_session: <aiohttp.client.ClientSession object at 0x102259090>
  • 补充信息:
    • 不设置trust_env时,连接正常
    • 代理服务处于运行且可访问状态
    • 已尝试添加TCPConnector创建ClientSession,问题仍未解决

内容的提问来源于stack exchange,提问作者andig

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.19 05:07:34