python network_error ai_generated true

aiohttp 客户端连接器 SSL 错误:版本号错误

aiohttp.client_exceptions.ClientConnectorSSLError: [SSL: WRONG_VERSION_NUMBER] wrong version number

ID: python/aiohttp-client-connector-ssl-handshake-error

其他格式: JSON · Markdown 中文 · English
80%修复率
83%置信度
0证据数
2025-11-18首次发现

版本兼容性

版本状态引入弃用备注
3.10 active
3.11 active

根因分析

服务器使用不兼容的 SSL/TLS 版本,或者客户端尝试使用 HTTPS 连接到 HTTP 服务器。

English

The server is using an incompatible SSL/TLS version, or the client is trying to connect with HTTPS to an HTTP server.

generic

解决方案

  1. 90% 成功率 Use the correct URL scheme (http:// instead of https://)
    async with session.get('http://example.com') as resp:
  2. 85% 成功率 Update the SSL context to use modern TLS versions
    import ssl
    ssl_context = ssl.create_default_context()
    ssl_context.minimum_version = ssl.TLSVersion.TLSv1_2
    connector = aiohttp.TCPConnector(ssl=ssl_context)
    async with aiohttp.ClientSession(connector=connector) as session:

无效尝试

常见但无效的做法:

  1. Disabling SSL verification with ssl=False 50% 失败

    This does not fix the version mismatch; it only bypasses certificate verification.

  2. Using a very old SSL context that forces TLS 1.0 60% 失败

    Many servers now reject outdated TLS versions due to security policies.