Skip to content

Introduce httpx.SSLError exception #3350

Open

Description

@pquentin

httpcore 1.0.6 was released with a change that now maps SSLError to httpcore.ConnectError. But I'm realizing now that this change only affects asyncio (with and without anyio). All other backends (sync, trio with and without anyio) already raised httpx.ConnectError. The current behavior is consistent across backends, as is shown by the following tests:

import asyncio
import contextlib
import traceback

import anyio
import httpx
import pytest
import trio


def sync_bad_ssl():
    client = httpx.Client()
    client.get("https://tls-v1-0.badssl.com:1010")


async def bad_ssl():
    client = httpx.AsyncClient()
    await client.get("https://tls-v1-0.badssl.com:1010")


def test_sync_bad_ssl():
    with pytest.raises(httpx.ConnectError):
        sync_bad_ssl()

# Fails with httpcore<1.0.6
@pytest.mark.asyncio
async def test_bad_ssl_asyncio():
    with pytest.raises(httpx.ConnectError):
        await bad_ssl()


@pytest.mark.trio
async def test_bad_ssl_trio():
    with pytest.raises(httpx.ConnectError):
        await bad_ssl()

# Fails with httpcore<1.0.6 and anyio_backend=asyncio
@pytest.mark.parametrize("anyio_backend", ["asyncio", "trio"])
@pytest.mark.anyio
async def test_bad_ssl_anyio():
    with pytest.raises(httpx.ConnectError):
        await bad_ssl()

However, it's not consistent with other HTTP libraries out there:

  • aiohttp raises aiohttp.client_exceptions.ClientSSLError
  • requests raises requests.exceptions.SSLError
  • urllib3 raises urllib3.exceptions.SSLError

As mentioned by Tom in the discussion, httpx should also be raising httpx.SSLError (a new subclass of httpx.RequestError), which would make it easier for downstream users to switch to httpx.

Activity

  1. lovelydinosaur commented on Oct 21, 2024

    @lovelydinosaur
    Member

    Thanks the neatly summarised issue @pquentin. 😎
    Presumably we need to start by resolving this in the underlying httpcore dependency since that doesn't have this distinction. Would you be interested dealing with an issue/PR there. (I can probably take it on otherwise)

  2. pquentin commented on Oct 21, 2024

    @pquentin
    ContributorAuthor

    Thank you for the offer but I feel that it would be best if you could take it on. 🙏

  3. added
    user-experience
    on Oct 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    user-experience

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions