prompt: We are currently solving the following issue within our repository. Here is the issue text:
  --- BEGIN ISSUE ---
  KeyError 'https,http' in async handling 1.31.0
  ### 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
  
  .
  
  --- END ISSUE ---
  
  Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
  --- BEGIN FILES ---
  Path: `sentry_sdk/integrations/_asgi_common.py`
  Content:
  ```
  1 import urllib
  2 
  3 from sentry_sdk.hub import _should_send_default_pii
  4 from sentry_sdk.integrations._wsgi_common import _filter_headers
  5 from sentry_sdk._types import TYPE_CHECKING
  6 
  7 if TYPE_CHECKING:
  8     from typing import Any
  9     from typing import Dict
  10     from typing import Optional
  11     from typing_extensions import Literal
  12 
  13 
  14 def _get_headers(asgi_scope):
  15     # type: (Any) -> Dict[str, str]
  16     """
  17     Extract headers from the ASGI scope, in the format that the Sentry protocol expects.
  18     """
  19     headers = {}  # type: Dict[str, str]
  20     for raw_key, raw_value in asgi_scope["headers"]:
  21         key = raw_key.decode("latin-1")
  22         value = raw_value.decode("latin-1")
  23         if key in headers:
  24             headers[key] = headers[key] + ", " + value
  25         else:
  26             headers[key] = value
  27 
  28     return headers
  29 
  30 
  31 def _get_url(asgi_scope, default_scheme, host):
  32     # type: (Dict[str, Any], Literal["ws", "http"], Optional[str]) -> str
  33     """
  34     Extract URL from the ASGI scope, without also including the querystring.
  35     """
  36     scheme = asgi_scope.get("scheme", default_scheme)
  37 
  38     server = asgi_scope.get("server", None)
  39     path = asgi_scope.get("root_path", "") + asgi_scope.get("path", "")
  40 
  41     if host:
  42         return "%s://%s%s" % (scheme, host, path)
  43 
  44     if server is not None:
  45         host, port = server
  46         default_port = {"http": 80, "https": 443, "ws": 80, "wss": 443}[scheme]
  47         if port != default_port:
  48             return "%s://%s:%s%s" % (scheme, host, port, path)
  49         return "%s://%s%s" % (scheme, host, path)
  50     return path
  51 
  52 
  53 def _get_query(asgi_scope):
  54     # type: (Any) -> Any
  55     """
  56     Extract querystring from the ASGI scope, in the format that the Sentry protocol expects.
  57     """
  58     qs = asgi_scope.get("query_string")
  59     if not qs:
  60         return None
  61     return urllib.parse.unquote(qs.decode("latin-1"))
  62 
  63 
  64 def _get_ip(asgi_scope):
  65     # type: (Any) -> str
  66     """
  67     Extract IP Address from the ASGI scope based on request headers with fallback to scope client.
  68     """
  69     headers = _get_headers(asgi_scope)
  70     try:
  71         return headers["x-forwarded-for"].split(",")[0].strip()
  72     except (KeyError, IndexError):
  73         pass
  74 
  75     try:
  76         return headers["x-real-ip"]
  77     except KeyError:
  78         pass
  79 
  80     return asgi_scope.get("client")[0]
  81 
  82 
  83 def _get_request_data(asgi_scope):
  84     # type: (Any) -> Dict[str, Any]
  85     """
  86     Returns data related to the HTTP request from the ASGI scope.
  87     """
  88     request_data = {}  # type: Dict[str, Any]
  89     ty = asgi_scope["type"]
  90     if ty in ("http", "websocket"):
  91         request_data["method"] = asgi_scope.get("method")
  92 
  93         request_data["headers"] = headers = _filter_headers(_get_headers(asgi_scope))
  94         request_data["query_string"] = _get_query(asgi_scope)
  95 
  96         request_data["url"] = _get_url(
  97             asgi_scope, "http" if ty == "http" else "ws", headers.get("host")
  98         )
  99 
  100     client = asgi_scope.get("client")
  101     if client and _should_send_default_pii():
  102         request_data["env"] = {"REMOTE_ADDR": _get_ip(asgi_scope)}
  103 
  104     return request_data
  105
  ```
  --- END FILES ---
  
  Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.
  
  Here is an example:
  
  ```diff
  diff --git a/examples/server_async.py b/examples/server_async.py
  --- a/examples/server_async.py
  +++ b/examples/server_async.py
  @@ -313,4 +313,4 @@
   
   
   if __name__ == "__main__":
  -    asyncio.run(run_async_server("."), debug=True)
  +    asyncio.run(run_async_server(), debug=True)
  diff --git a/examples/server_sync.py b/examples/server_sync.py
  --- a/examples/server_sync.py
  +++ b/examples/server_sync.py
  @@ -313,5 +313,5 @@
   
   
   if __name__ == "__main__":
  -    server = run_sync_server(".")
  +    server = run_sync_server()
       server.shutdown()
  
  ```
  
golden_diff: diff --git a/sentry_sdk/integrations/_asgi_common.py b/sentry_sdk/integrations/_asgi_common.py
  --- a/sentry_sdk/integrations/_asgi_common.py
  +++ b/sentry_sdk/integrations/_asgi_common.py
  @@ -43,7 +43,7 @@
   
       if server is not None:
           host, port = server
  -        default_port = {"http": 80, "https": 443, "ws": 80, "wss": 443}[scheme]
  +        default_port = {"http": 80, "https": 443, "ws": 80, "wss": 443}.get(scheme)
           if port != default_port:
               return "%s://%s:%s%s" % (scheme, host, port, path)
           return "%s://%s%s" % (scheme, host, path)
  
verification_info: {"golden_diff": "diff --git a/sentry_sdk/integrations/_asgi_common.py b/sentry_sdk/integrations/_asgi_common.py\n--- a/sentry_sdk/integrations/_asgi_common.py\n+++ b/sentry_sdk/integrations/_asgi_common.py\n@@ -43,7 +43,7 @@\n \n     if server is not None:\n         host, port = server\n-        default_port = {\"http\": 80, \"https\": 443, \"ws\": 80, \"wss\": 443}[scheme]\n+        default_port = {\"http\": 80, \"https\": 443, \"ws\": 80, \"wss\": 443}.get(scheme)\n         if port != default_port:\n             return \"%s://%s:%s%s\" % (scheme, host, port, path)\n         return \"%s://%s%s\" % (scheme, host, path)\n", "issue": "KeyError 'https,http' in async handling 1.31.0\n### How do you use Sentry?\n\nSelf-hosted/on-premise\n\n### Version\n\n1.31.0\n\n### Steps to Reproduce\n\nI'm running sentry and uvicorn. We also have django-channels. On upgrading to 1.31.0 I'm getting the following:\r\n\r\n```\r\nTraceback (most recent call last):\r\nFile \"/home/vcap/deps/0/python/lib/python3.9/site-packages/uvicorn/protocols/http/httptools_impl.py\", line 426, in run_asgi\r\nresult = await app( # type: ignore[func-returns-value]\r\nFile \"/home/vcap/deps/0/python/lib/python3.9/site-packages/uvicorn/middleware/proxy_headers.py\", line 84, in __call__\r\nreturn await self.app(scope, receive, send)\r\nFile \"/home/vcap/deps/0/python/lib/python3.9/site-packages/channels/routing.py\", line 62, in __call__\r\nreturn await application(scope, receive, send)\r\nFile \"/home/vcap/deps/0/python/lib/python3.9/site-packages/sentry_sdk/integrations/django/asgi.py\", line 40, in sentry_patched_asgi_handler\r\nreturn await middleware(scope, receive, send)\r\nFile \"/home/vcap/deps/0/python/lib/python3.9/site-packages/sentry_sdk/integrations/asgi.py\", line 146, in _run_asgi3\r\nreturn await self._run_app(scope, receive, send, asgi_version=3)\r\nFile \"/home/vcap/deps/0/python/lib/python3.9/site-packages/sentry_sdk/integrations/asgi.py\", line 178, in _run_app\r\n) = self._get_transaction_name_and_source(\r\nFile \"/home/vcap/deps/0/python/lib/python3.9/site-packages/sentry_sdk/integrations/asgi.py\", line 293, in _get_transaction_name_and_source\r\nname = _get_url(asgi_scope, \"http\" if ty == \"http\" else \"ws\", host=None)\r\nFile \"/home/vcap/deps/0/python/lib/python3.9/site-packages/sentry_sdk/integrations/_asgi_common.py\", line 46, in _get_url\r\ndefault_port = {\"http\": 80, \"https\": 443, \"ws\": 80, \"wss\": 443}[scheme]\r\nKeyError: 'https,http'\r\n```\r\n\r\nI did not research further but it seems to be caused by the recent overhaul of the code (#2335)\n\n### Expected Result\n\nNo exception\n\n### Actual Result\n\n.\n", "before_files": [{"content": "import urllib\n\nfrom sentry_sdk.hub import _should_send_default_pii\nfrom sentry_sdk.integrations._wsgi_common import _filter_headers\nfrom sentry_sdk._types import TYPE_CHECKING\n\nif TYPE_CHECKING:\n    from typing import Any\n    from typing import Dict\n    from typing import Optional\n    from typing_extensions import Literal\n\n\ndef _get_headers(asgi_scope):\n    # type: (Any) -> Dict[str, str]\n    \"\"\"\n    Extract headers from the ASGI scope, in the format that the Sentry protocol expects.\n    \"\"\"\n    headers = {}  # type: Dict[str, str]\n    for raw_key, raw_value in asgi_scope[\"headers\"]:\n        key = raw_key.decode(\"latin-1\")\n        value = raw_value.decode(\"latin-1\")\n        if key in headers:\n            headers[key] = headers[key] + \", \" + value\n        else:\n            headers[key] = value\n\n    return headers\n\n\ndef _get_url(asgi_scope, default_scheme, host):\n    # type: (Dict[str, Any], Literal[\"ws\", \"http\"], Optional[str]) -> str\n    \"\"\"\n    Extract URL from the ASGI scope, without also including the querystring.\n    \"\"\"\n    scheme = asgi_scope.get(\"scheme\", default_scheme)\n\n    server = asgi_scope.get(\"server\", None)\n    path = asgi_scope.get(\"root_path\", \"\") + asgi_scope.get(\"path\", \"\")\n\n    if host:\n        return \"%s://%s%s\" % (scheme, host, path)\n\n    if server is not None:\n        host, port = server\n        default_port = {\"http\": 80, \"https\": 443, \"ws\": 80, \"wss\": 443}[scheme]\n        if port != default_port:\n            return \"%s://%s:%s%s\" % (scheme, host, port, path)\n        return \"%s://%s%s\" % (scheme, host, path)\n    return path\n\n\ndef _get_query(asgi_scope):\n    # type: (Any) -> Any\n    \"\"\"\n    Extract querystring from the ASGI scope, in the format that the Sentry protocol expects.\n    \"\"\"\n    qs = asgi_scope.get(\"query_string\")\n    if not qs:\n        return None\n    return urllib.parse.unquote(qs.decode(\"latin-1\"))\n\n\ndef _get_ip(asgi_scope):\n    # type: (Any) -> str\n    \"\"\"\n    Extract IP Address from the ASGI scope based on request headers with fallback to scope client.\n    \"\"\"\n    headers = _get_headers(asgi_scope)\n    try:\n        return headers[\"x-forwarded-for\"].split(\",\")[0].strip()\n    except (KeyError, IndexError):\n        pass\n\n    try:\n        return headers[\"x-real-ip\"]\n    except KeyError:\n        pass\n\n    return asgi_scope.get(\"client\")[0]\n\n\ndef _get_request_data(asgi_scope):\n    # type: (Any) -> Dict[str, Any]\n    \"\"\"\n    Returns data related to the HTTP request from the ASGI scope.\n    \"\"\"\n    request_data = {}  # type: Dict[str, Any]\n    ty = asgi_scope[\"type\"]\n    if ty in (\"http\", \"websocket\"):\n        request_data[\"method\"] = asgi_scope.get(\"method\")\n\n        request_data[\"headers\"] = headers = _filter_headers(_get_headers(asgi_scope))\n        request_data[\"query_string\"] = _get_query(asgi_scope)\n\n        request_data[\"url\"] = _get_url(\n            asgi_scope, \"http\" if ty == \"http\" else \"ws\", headers.get(\"host\")\n        )\n\n    client = asgi_scope.get(\"client\")\n    if client and _should_send_default_pii():\n        request_data[\"env\"] = {\"REMOTE_ADDR\": _get_ip(asgi_scope)}\n\n    return request_data\n", "path": "sentry_sdk/integrations/_asgi_common.py"}], "after_files": [{"content": "import urllib\n\nfrom sentry_sdk.hub import _should_send_default_pii\nfrom sentry_sdk.integrations._wsgi_common import _filter_headers\nfrom sentry_sdk._types import TYPE_CHECKING\n\nif TYPE_CHECKING:\n    from typing import Any\n    from typing import Dict\n    from typing import Optional\n    from typing_extensions import Literal\n\n\ndef _get_headers(asgi_scope):\n    # type: (Any) -> Dict[str, str]\n    \"\"\"\n    Extract headers from the ASGI scope, in the format that the Sentry protocol expects.\n    \"\"\"\n    headers = {}  # type: Dict[str, str]\n    for raw_key, raw_value in asgi_scope[\"headers\"]:\n        key = raw_key.decode(\"latin-1\")\n        value = raw_value.decode(\"latin-1\")\n        if key in headers:\n            headers[key] = headers[key] + \", \" + value\n        else:\n            headers[key] = value\n\n    return headers\n\n\ndef _get_url(asgi_scope, default_scheme, host):\n    # type: (Dict[str, Any], Literal[\"ws\", \"http\"], Optional[str]) -> str\n    \"\"\"\n    Extract URL from the ASGI scope, without also including the querystring.\n    \"\"\"\n    scheme = asgi_scope.get(\"scheme\", default_scheme)\n\n    server = asgi_scope.get(\"server\", None)\n    path = asgi_scope.get(\"root_path\", \"\") + asgi_scope.get(\"path\", \"\")\n\n    if host:\n        return \"%s://%s%s\" % (scheme, host, path)\n\n    if server is not None:\n        host, port = server\n        default_port = {\"http\": 80, \"https\": 443, \"ws\": 80, \"wss\": 443}.get(scheme)\n        if port != default_port:\n            return \"%s://%s:%s%s\" % (scheme, host, port, path)\n        return \"%s://%s%s\" % (scheme, host, path)\n    return path\n\n\ndef _get_query(asgi_scope):\n    # type: (Any) -> Any\n    \"\"\"\n    Extract querystring from the ASGI scope, in the format that the Sentry protocol expects.\n    \"\"\"\n    qs = asgi_scope.get(\"query_string\")\n    if not qs:\n        return None\n    return urllib.parse.unquote(qs.decode(\"latin-1\"))\n\n\ndef _get_ip(asgi_scope):\n    # type: (Any) -> str\n    \"\"\"\n    Extract IP Address from the ASGI scope based on request headers with fallback to scope client.\n    \"\"\"\n    headers = _get_headers(asgi_scope)\n    try:\n        return headers[\"x-forwarded-for\"].split(\",\")[0].strip()\n    except (KeyError, IndexError):\n        pass\n\n    try:\n        return headers[\"x-real-ip\"]\n    except KeyError:\n        pass\n\n    return asgi_scope.get(\"client\")[0]\n\n\ndef _get_request_data(asgi_scope):\n    # type: (Any) -> Dict[str, Any]\n    \"\"\"\n    Returns data related to the HTTP request from the ASGI scope.\n    \"\"\"\n    request_data = {}  # type: Dict[str, Any]\n    ty = asgi_scope[\"type\"]\n    if ty in (\"http\", \"websocket\"):\n        request_data[\"method\"] = asgi_scope.get(\"method\")\n\n        request_data[\"headers\"] = headers = _filter_headers(_get_headers(asgi_scope))\n        request_data[\"query_string\"] = _get_query(asgi_scope)\n\n        request_data[\"url\"] = _get_url(\n            asgi_scope, \"http\" if ty == \"http\" else \"ws\", headers.get(\"host\")\n        )\n\n    client = asgi_scope.get(\"client\")\n    if client and _should_send_default_pii():\n        request_data[\"env\"] = {\"REMOTE_ADDR\": _get_ip(asgi_scope)}\n\n    return request_data\n", "path": "sentry_sdk/integrations/_asgi_common.py"}]}