question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Starlette integration requires python-multipart

See original GitHub issue

How do you use Sentry?

Sentry Saas (sentry.io)

Version

1.8.0

Steps to Reproduce

Using the Starlette/FastAPI integration while python-multipart isn’t installed raises an exception. It’s an optional dependency for Starlette, but not optional for sentry-sdk.

sentry_sdk.init(
    dsn=settings.SENTRY_DSN,
    integrations=[StarletteIntegration(), FastApiIntegration()],
)

This can be fixed by gathering form data conditionally.

Expected Result

No exception.

Actual Result

Sending any request, even a GET, raises an exceptions, here’s the relevant part of the stacktrace:

.venv/lib/python3.10/site-packages/fastapi/applications.py:269: in __call__
    await super().__call__(scope, receive, send)
.venv/lib/python3.10/site-packages/sentry_sdk/integrations/starlette.py:268: in _sentry_patched_asgi_app
    return await middleware(scope, receive, send)
.venv/lib/python3.10/site-packages/sentry_sdk/integrations/asgi.py:126: in _run_asgi3
    return await self._run_app(scope, lambda: self.app(scope, receive, send))
.venv/lib/python3.10/site-packages/sentry_sdk/integrations/asgi.py:176: in _run_app
    raise exc from None
.venv/lib/python3.10/site-packages/sentry_sdk/integrations/asgi.py:171: in _run_app
    return await callback()
.venv/lib/python3.10/site-packages/sentry_sdk/integrations/starlette.py:268: in _sentry_patched_asgi_app
    return await middleware(scope, receive, send)
.venv/lib/python3.10/site-packages/sentry_sdk/integrations/asgi.py:126: in _run_asgi3
    return await self._run_app(scope, lambda: self.app(scope, receive, send))
.venv/lib/python3.10/site-packages/sentry_sdk/integrations/asgi.py:137: in _run_app
    raise exc from None
.venv/lib/python3.10/site-packages/sentry_sdk/integrations/asgi.py:134: in _run_app
    return await callback()
.venv/lib/python3.10/site-packages/starlette/applications.py:124: in __call__
    await self.middleware_stack(scope, receive, send)
.venv/lib/python3.10/site-packages/sentry_sdk/integrations/fastapi.py:122: in __call__
    await self.app(scope, receive, send)
.venv/lib/python3.10/site-packages/sentry_sdk/integrations/starlette.py:432: in __call__
    info = await extractor.extract_request_info()
.venv/lib/python3.10/site-packages/sentry_sdk/integrations/starlette.py:305: in extract_request_info
    parsed_body = await self.parsed_body()
.venv/lib/python3.10/site-packages/sentry_sdk/integrations/starlette.py:363: in parsed_body
    form = await self.form()
.venv/lib/python3.10/site-packages/sentry_sdk/integrations/starlette.py:342: in form
    return await self.request.form()
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
self = <starlette.requests.Request object at 0x7ff9da7f7610>
    async def form(self) -> FormData:
        if not hasattr(self, "_form"):
>           assert (
                parse_options_header is not None
            ), "The `python-multipart` library must be installed to use form parsing."
E           AssertionError: The `python-multipart` library must be installed to use form parsing.
.venv/lib/python3.10/site-packages/starlette/requests.py:247: AssertionError

Issue Analytics

  • State:closed
  • Created a year ago
  • Reactions:4
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

7reactions
matyasrichtercommented, Jul 26, 2022

@antonpirker Any estimate on when this could make it into a release? 🙏

1reaction
juanbenitoprcommented, Jul 29, 2022

@matyasrichter I think the problem is already solved in the release 1.9.0 😃

https://github.com/getsentry/sentry-python/tree/1.9.0

Read more comments on GitHub >

github_iconTop Results From Across the Web

The `python-multipart` library must be installed to use form ...
AssertionError: The `python-multipart` library must be installed to use form parsing.``` --- Name: starlette Version: 0.11.4 Summary: The ...
Read more >
Starlette
Starlette is a lightweight ASGI framework/toolkit, which is ideal for building async web services in Python. It is production-ready, and gives you the...
Read more >
Starlette - Rollbar Docs
python-multipart package that is required for parsing request body content (this is the Starlette requirement). Run the examples (saved as a
Read more >
Starlette - Sentry Documentation
The Starlette integration adds support for the Starlette Framework . The Sentry SDK automatically enables support for Starlette if you have the starlette...
Read more >
Source code for bentoml._internal.io_descriptors.multipart
Install with ``pip install requests-toolbelt``. .. code-block:: python :caption: `request.py` import requests from requests_toolbelt.multipart.encoder ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found