# Buggy code
def _sentry_start_response(
    old_start_response, span, status, response_headers, exc_info=None
):
    # type: (Callable[[str, U, Optional[E]], T], Span, str, U, Optional[E]) -> T
    with capture_internal_exceptions():
        status_int = int(status.split(" ", 1)[0])
        span.set_http_status(status_int)

    return old_start_response(status, response_headers, exc_info)


# Traceback (TypeError)
Traceback (most recent call last):
File "/var/www/pixiu.40huo.cn/pixiu/venv/lib/python3.8/site-packages/apscheduler/executors/base_py3.py", line 29, in run_coroutine_job
retval = await job.func(*job.args, **job.kwargs)
File "/var/www/pixiu.40huo.cn/pixiu/backend/scheduler.py", line 96, in refresh_task
req = await fetch_resource_list(loop=loop)
File "/var/www/pixiu.40huo.cn/pixiu/backend/scheduler.py", line 27, in fetch_resource_list
req = await loop.run_in_executor(executor, send_req, "get", reverse(viewname="resource-list"))
File "/usr/lib/python3.8/concurrent/futures/thread.py", line 57, in run
result = self.fn(*self.args, **self.kwargs)
File "/var/www/pixiu.40huo.cn/pixiu/utils/http_req.py", line 37, in send_req
return client.get(url=abs_url, headers=headers)
File "/var/www/pixiu.40huo.cn/pixiu/venv/lib/python3.8/site-packages/requests/sessions.py", line 546, in get
return self.request('GET', url, **kwargs)
File "/var/www/pixiu.40huo.cn/pixiu/venv/lib/python3.8/site-packages/rest_framework/test.py", line 115, in request
return super().request(method, url, *args, **kwargs)
File "/var/www/pixiu.40huo.cn/pixiu/venv/lib/python3.8/site-packages/requests/sessions.py", line 533, in request
resp = self.send(prep, **send_kwargs)
File "/var/www/pixiu.40huo.cn/pixiu/venv/lib/python3.8/site-packages/requests/sessions.py", line 646, in send
r = adapter.send(request, **kwargs)
File "/var/www/pixiu.40huo.cn/pixiu/venv/lib/python3.8/site-packages/rest_framework/test.py", line 93, in send
wsgi_response = self.app(environ, start_response)
File "/var/www/pixiu.40huo.cn/pixiu/venv/lib/python3.8/site-packages/sentry_sdk/integrations/django/__init__.py", line 101, in sentry_patched_wsgi_handler
return SentryWsgiMiddleware(lambda *a, **kw: old_app(self, *a, **kw))(
File "/var/www/pixiu.40huo.cn/pixiu/venv/lib/python3.8/site-packages/sentry_sdk/integrations/wsgi.py", line 106, in __call__
reraise(*_capture_exception(hub))
File "/var/www/pixiu.40huo.cn/pixiu/venv/lib/python3.8/site-packages/sentry_sdk/_compat.py", line 54, in reraise
raise value
File "/var/www/pixiu.40huo.cn/pixiu/venv/lib/python3.8/site-packages/sentry_sdk/integrations/wsgi.py", line 101, in __call__
rv = self.app(
File "/var/www/pixiu.40huo.cn/pixiu/venv/lib/python3.8/site-packages/sentry_sdk/integrations/django/__init__.py", line 101, in <lambda>
return SentryWsgiMiddleware(lambda *a, **kw: old_app(self, *a, **kw))(
File "/var/www/pixiu.40huo.cn/pixiu/venv/lib/python3.8/site-packages/django/core/handlers/wsgi.py", line 142, in __call__
start_response(status, response_headers)
File "/var/www/pixiu.40huo.cn/pixiu/venv/lib/python3.8/site-packages/sentry_sdk/integrations/wsgi.py", line 121, in _sentry_start_response
return old_start_response(status, response_headers, exc_info)
TypeError: start_response() takes 2 positional arguments but 3 were given

# Fixed code
def _sentry_start_response(
    old_start_response,  # type: StartResponse
    span,  # type: Span
    status,  # type: str
    response_headers,  # type: WsgiResponseHeaders
    exc_info=None,  # type: Optional[WsgiExcInfo]
):
    # type: (...) -> WsgiResponseIter
    with capture_internal_exceptions():
        status_int = int(status.split(" ", 1)[0])
        span.set_http_status(status_int)

    if exc_info is None:
        # The Django Rest Framework WSGI test client, and likely other
        # (incorrect) implementations, cannot deal with the exc_info argument
        # if one is present. Avoid providing a third argument if not necessary.
        return old_start_response(status, response_headers)
    else:
        return old_start_response(status, response_headers, exc_info)