Skip to content

KeyError 'https,http' in async handling 1.31.0 #2370

Closed

Description

@vanschelven

How do you use Sentry?

Self-hosted/on-premise

Version

1.31.0

Steps to Reproduce

I'm running sentry and uvicorn. We also have django-channels. On upgrading to 1.31.0 I'm getting the following:

Traceback (most recent call last):
File "/home/vcap/deps/0/python/lib/python3.9/site-packages/uvicorn/protocols/http/httptools_impl.py", line 426, in run_asgi
result = await app( # type: ignore[func-returns-value]
File "/home/vcap/deps/0/python/lib/python3.9/site-packages/uvicorn/middleware/proxy_headers.py", line 84, in __call__
return await self.app(scope, receive, send)
File "/home/vcap/deps/0/python/lib/python3.9/site-packages/channels/routing.py", line 62, in __call__
return await application(scope, receive, send)
File "/home/vcap/deps/0/python/lib/python3.9/site-packages/sentry_sdk/integrations/django/asgi.py", line 40, in sentry_patched_asgi_handler
return await middleware(scope, receive, send)
File "/home/vcap/deps/0/python/lib/python3.9/site-packages/sentry_sdk/integrations/asgi.py", line 146, in _run_asgi3
return await self._run_app(scope, receive, send, asgi_version=3)
File "/home/vcap/deps/0/python/lib/python3.9/site-packages/sentry_sdk/integrations/asgi.py", line 178, in _run_app
) = self._get_transaction_name_and_source(
File "/home/vcap/deps/0/python/lib/python3.9/site-packages/sentry_sdk/integrations/asgi.py", line 293, in _get_transaction_name_and_source
name = _get_url(asgi_scope, "http" if ty == "http" else "ws", host=None)
File "/home/vcap/deps/0/python/lib/python3.9/site-packages/sentry_sdk/integrations/_asgi_common.py", line 46, in _get_url
default_port = {"http": 80, "https": 443, "ws": 80, "wss": 443}[scheme]
KeyError: 'https,http'

I did not research further but it seems to be caused by the recent overhaul of the code (#2335)

Expected Result

No exception

Actual Result

.

Activity

  1. moved this to Waiting for: Product Owner in GitHub Issues with 👀on Sep 14, 2023
  2. vanschelven commented on Sep 14, 2023

    @vanschelven
    ContributorAuthor

    I'm behind a proxy, and the proxy has x-forwarded-proto: https. in instances of this error occurring the header x-forwarded-proto: https,http is sent.

  3. changed the title [-]KeyError 'http,https' in async handling 1.31.0[/-] [+]KeyError 'https,http' in async handling 1.31.0[/+] on Sep 14, 2023
  4. vanschelven commented on Sep 14, 2023

    @vanschelven
    ContributorAuthor

    In channels (4.0.0) in the following line scheme already has the value https,http:

    File "/home/vcap/deps/0/python/lib/python3.9/site-packages/channels/routing.py", line 62, in __call__

  5. vanschelven commented on Sep 14, 2023

    @vanschelven
    ContributorAuthor

    The value of x-forwarded-proto comes from the Cloud Foundry gorouter:

    https://docs.cloudfoundry.org/concepts/http-routing.html#X-Forwarded-Proto

    I can't find an actual standard for this header, but I don't think it's unique and it would be good if sentry-sdk didn't introduce an error here.

  6. vanschelven commented on Sep 14, 2023

    @vanschelven
    ContributorAuthor

    Arguably, this is actually a problem in uvicorn; I've started a discussion there

  7. vanschelven commented on Sep 14, 2023

    @vanschelven
    ContributorAuthor

    Thinking this through a bit more, I'm becoming of the opinion that upstream problem or not, the sentry-sdk should simply be robust for this. My thinking is: it should never be so that the introduction of a framework to detect errors is in itself what causes failure.

  8. antonpirker commented on Sep 15, 2023

    @antonpirker
    Contributor

    Hey @vanschelven !

    Thanks for reporting this and also submitting a PR fixing it in one go! Awesome!
    This will be merged and then release with the next version of the Python SDK.

  9. moved this from Waiting for: Product Owner to No status in GitHub Issues with 👀on Sep 15, 2023
  10. self-assigned this
    on Sep 15, 2023
  11. ghost added on Aug 13, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions