Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce httpx.SSLError exception #3350

Open
1 task done
pquentin opened this issue Oct 18, 2024 · 2 comments
Open
1 task done

Introduce httpx.SSLError exception #3350

pquentin opened this issue Oct 18, 2024 · 2 comments
Labels
user-experience Ensuring that users have a good experience using the library

Comments

@pquentin
Copy link
Contributor

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.

@tomchristie
Copy link
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)

@pquentin
Copy link
Contributor Author

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

@tomchristie tomchristie added the user-experience Ensuring that users have a good experience using the library label Oct 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
user-experience Ensuring that users have a good experience using the library
Projects
None yet
Development

No branches or pull requests

3 participants
@pquentin @tomchristie and others