getsentry / sentry-python

The official Python SDK for Sentry.io
https://sentry.io/for/python/
MIT License
1.85k stars 481 forks source link

FastAPI file upload not working with sentry after 1.9.6 #1595

Closed dearkafka closed 1 year ago

dearkafka commented 1 year ago

How do you use Sentry?

Sentry Saas (sentry.io)

Version

1.9.6

Steps to Reproduce

from fastapi import FastAPI, File, UploadFile
from PIL import Image
import uvicorn
import io

import sentry_sdk
from sentry_sdk.integrations.starlette import StarletteIntegration
from sentry_sdk.integrations.fastapi import FastApiIntegration

sentry_sdk.init(
    dsn=SECRET,
    release="server",
    integrations=[
        StarletteIntegration(),
        FastApiIntegration(),
    ],
    attach_stacktrace=True,
    request_bodies="always",
    send_default_pii=True,
    traces_sample_rate=0.0,
)

app = FastAPI()

@app.post("/predict")
async def predict(file: UploadFile = File(default=None)):
    contents = await file.read()
    Image.open(io.BytesIO(contents)).convert("RGB")
    return {"result": "ok"}

uvicorn.run(app, host="0.0.0.0", port=8888, loop="asyncio", lifespan="on")

Expected Result

{"result": "ok"}

Actual Result

Please remove 'SentryAsgiMiddleware' from your project.
See https://docs.sentry.io/platforms/python/guides/asgi/ for more information.

so, when disabling sentry - all works fine, when adding sentry - it breaks. apparently sentry messes up content of uploaded file.

vladanpaunovic commented 1 year ago

@dearkafka, we released 1.9.7, https://github.com/getsentry/sentry-python/blob/master/CHANGELOG.md#197. You can give it a try and it may result in a success for you.

RockBomber commented 1 year ago

with version 1.9.8 still got the error.

vladanpaunovic commented 1 year ago

Thanks @RockBomber! We identified this a few days ago too. It's on our backlog and the team will be on it soon.

tristan commented 1 year ago

We managed to work around this problem for now by adding await file.seek(0) before the await file.read() call.

antonpirker commented 1 year ago

Hey @dearkafka ! I have now created you sample project like this: sample-code

(note that I have NOT specified the integrations, because they are now detected automatically!)

I have then uploaded an image with curl and it worked:

Screenshot 2022-09-30 at 16 44 55

Could you please retry with the newest SDK version and tell me if it still does not work?

Thanks!

RockBomber commented 1 year ago

@antonpirker unfortunately I cannot say it worked(

my sample:

from fastapi import FastAPI, File, UploadFile
from PIL import Image
import uvicorn
import io

import sentry_sdk

sentry_sdk.init(
    dsn=SECRET,
    traces_sample_rate=1.0,
)

app = FastAPI()

@app.post("/predict")
async def predict(file: UploadFile = File(default=None)):
    contents = await file.read()
    Image.open(io.BytesIO(contents)).convert("RGB")
    return {"result": "ok"}

if __name__ == '__main__':
    uvicorn.run(app, host="0.0.0.0", port=8888, loop="asyncio", lifespan="on")

and with this a I have an error

But if I add await file.seek(0) before read it works

I have installed packages: sentry-sdk==1.9.9 fastapi==0.85.0

Python 3.10.6

antonpirker commented 1 year ago

Hey @RockBomber !

Sorry, I can not reproduce this. I did everything exactly like you did, but for me it works: Screenshot 2022-10-03 at 10 13 19

Can you please add debug=True to your call to sentry_sdk.init() and then send me the output of the terminal in case of error? this would help a lot! Thanks!

RockBomber commented 1 year ago

output with debug:

 [sentry] DEBUG: Setting up integrations (with default = True)
 [sentry] DEBUG: Did not import default integration sentry_sdk.integrations.django.DjangoIntegration: Django not installed
 [sentry] DEBUG: Did not import default integration sentry_sdk.integrations.flask.FlaskIntegration: Flask is not installed
 [sentry] DEBUG: Did not import default integration sentry_sdk.integrations.bottle.BottleIntegration: Bottle not installed
 [sentry] DEBUG: Did not import default integration sentry_sdk.integrations.falcon.FalconIntegration: Falcon not installed
 [sentry] DEBUG: Did not import default integration sentry_sdk.integrations.sanic.SanicIntegration: Sanic not installed
 [sentry] DEBUG: Did not import default integration sentry_sdk.integrations.celery.CeleryIntegration: Celery not installed
 [sentry] DEBUG: Did not import default integration sentry_sdk.integrations.rq.RqIntegration: RQ not installed
 [sentry] DEBUG: Did not import default integration sentry_sdk.integrations.tornado.TornadoIntegration: Tornado not installed
 [sentry] DEBUG: Did not import default integration sentry_sdk.integrations.sqlalchemy.SqlalchemyIntegration: SQLAlchemy not installed.
 [sentry] DEBUG: Did not import default integration sentry_sdk.integrations.pyramid.PyramidIntegration: Pyramid not installed
 [sentry] DEBUG: Setting up previously not enabled integration logging
 [sentry] DEBUG: Setting up previously not enabled integration stdlib
 [sentry] DEBUG: Setting up previously not enabled integration excepthook
 [sentry] DEBUG: Setting up previously not enabled integration dedupe
 [sentry] DEBUG: Setting up previously not enabled integration atexit
 [sentry] DEBUG: Setting up previously not enabled integration modules
 [sentry] DEBUG: Setting up previously not enabled integration argv
 [sentry] DEBUG: Setting up previously not enabled integration threading
 [sentry] DEBUG: Setting up previously not enabled integration starlette
 [sentry] DEBUG: Setting up previously not enabled integration fastapi
 [sentry] DEBUG: Setting up previously not enabled integration aiohttp
 [sentry] DEBUG: Setting up previously not enabled integration redis
 [sentry] DEBUG: Setting up previously not enabled integration boto3
 [sentry] DEBUG: Enabling integration logging
 [sentry] DEBUG: Enabling integration stdlib
 [sentry] DEBUG: Enabling integration excepthook
 [sentry] DEBUG: Enabling integration dedupe
 [sentry] DEBUG: Enabling integration atexit
 [sentry] DEBUG: Enabling integration modules
 [sentry] DEBUG: Enabling integration argv
 [sentry] DEBUG: Enabling integration threading
 [sentry] DEBUG: Enabling integration starlette
 [sentry] DEBUG: Enabling integration fastapi
 [sentry] DEBUG: Enabling integration aiohttp
 [sentry] DEBUG: Enabling integration redis
 [sentry] DEBUG: Enabling integration boto3
INFO:     Started server process [15665]
INFO:     Waiting for application startup.
 [sentry] DEBUG: [Tracing] Starting <asgi.server> transaction <generic ASGI request>
INFO:     Application startup complete.
INFO:     Uvicorn running on http://0.0.0.0:8888 (Press CTRL+C to quit)
 [sentry] DEBUG: [Tracing] Starting <http.server> transaction <generic ASGI request>
INFO:     127.0.0.1:36646 - "POST /predict HTTP/1.1" 500 Internal Server Error
 [sentry] DEBUG: Sending event, type:null level:error event_id:6efc74ddb4a2494a805f91dfcf168590 project:3 host:<SECRET_HOST>
ERROR:    Exception in ASGI application
Traceback (most recent call last):
  File "/home/user/dev/project/.venv/lib/python3.10/site-packages/uvicorn/protocols/http/h11_impl.py", line 404, in run_asgi
    result = await app(  # type: ignore[func-returns-value]
  File "/home/user/dev/project/.venv/lib/python3.10/site-packages/uvicorn/middleware/proxy_headers.py", line 78, in __call__
    return await self.app(scope, receive, send)
  File "/home/user/dev/project/.venv/lib/python3.10/site-packages/fastapi/applications.py", line 269, in __call__
    await super().__call__(scope, receive, send)
  File "/home/user/dev/project/.venv/lib/python3.10/site-packages/sentry_sdk/integrations/starlette.py", line 293, in _sentry_patched_asgi_app
    return await middleware(scope, receive, send)
  File "/home/user/dev/project/.venv/lib/python3.10/site-packages/sentry_sdk/integrations/asgi.py", line 138, in _run_asgi3
    return await self._run_app(scope, lambda: self.app(scope, receive, send))
  File "/home/user/dev/project/.venv/lib/python3.10/site-packages/sentry_sdk/integrations/asgi.py", line 187, in _run_app
    raise exc from None
  File "/home/user/dev/project/.venv/lib/python3.10/site-packages/sentry_sdk/integrations/asgi.py", line 182, in _run_app
    return await callback()
  File "/home/user/dev/project/.venv/lib/python3.10/site-packages/starlette/applications.py", line 124, in __call__
    await self.middleware_stack(scope, receive, send)
  File "/home/user/dev/project/.venv/lib/python3.10/site-packages/sentry_sdk/integrations/starlette.py", line 98, in _create_span_call
    await old_call(*args, **kwargs)
  File "/home/user/dev/project/.venv/lib/python3.10/site-packages/starlette/middleware/errors.py", line 184, in __call__
    raise exc
  File "/home/user/dev/project/.venv/lib/python3.10/site-packages/starlette/middleware/errors.py", line 162, in __call__
    await self.app(scope, receive, _send)
  File "/home/user/dev/project/.venv/lib/python3.10/site-packages/sentry_sdk/integrations/starlette.py", line 191, in _sentry_exceptionmiddleware_call
    await old_call(self, scope, receive, send)
  File "/home/user/dev/project/.venv/lib/python3.10/site-packages/sentry_sdk/integrations/starlette.py", line 98, in _create_span_call
    await old_call(*args, **kwargs)
  File "/home/user/dev/project/.venv/lib/python3.10/site-packages/starlette/exceptions.py", line 93, in __call__
    raise exc
  File "/home/user/dev/project/.venv/lib/python3.10/site-packages/starlette/exceptions.py", line 82, in __call__
    await self.app(scope, receive, sender)
  File "/home/user/dev/project/.venv/lib/python3.10/site-packages/sentry_sdk/integrations/starlette.py", line 98, in _create_span_call
    await old_call(*args, **kwargs)
  File "/home/user/dev/project/.venv/lib/python3.10/site-packages/fastapi/middleware/asyncexitstack.py", line 21, in __call__
    raise e
  File "/home/user/dev/project/.venv/lib/python3.10/site-packages/fastapi/middleware/asyncexitstack.py", line 18, in __call__
    await self.app(scope, receive, send)
  File "/home/user/dev/project/.venv/lib/python3.10/site-packages/starlette/routing.py", line 670, in __call__
    await route.handle(scope, receive, send)
  File "/home/user/dev/project/.venv/lib/python3.10/site-packages/starlette/routing.py", line 266, in handle
    await self.app(scope, receive, send)
  File "/home/user/dev/project/.venv/lib/python3.10/site-packages/starlette/routing.py", line 65, in app
    response = await func(request)
  File "/home/user/dev/project/.venv/lib/python3.10/site-packages/sentry_sdk/integrations/fastapi.py", line 106, in _sentry_app
    return await old_app(*args, **kwargs)
  File "/home/user/dev/project/.venv/lib/python3.10/site-packages/fastapi/routing.py", line 231, in app
    raw_response = await run_endpoint_function(
  File "/home/user/dev/project/.venv/lib/python3.10/site-packages/fastapi/routing.py", line 160, in run_endpoint_function
    return await dependant.call(**values)
  File "/home/user/dev/project/_check_sentry.py", line 20, in predict
    Image.open(io.BytesIO(contents)).convert("RGB")
  File "/home/user/dev/project/.venv/lib/python3.10/site-packages/PIL/Image.py", line 3147, in open
    raise UnidentifiedImageError(
PIL.UnidentifiedImageError: cannot identify image file <_io.BytesIO object at 0x7fe7aac73dd0>
 [sentry] INFO: event processor (<function DedupeIntegration.setup_once.<locals>.processor at 0x7fe7ab146830>) dropped event ({'level': 'error', 'exception': {'values': [{'module': 'PIL', 'type': 'UnidentifiedImageError', 'value': 'cannot identify image file <_io.BytesIO object at 0x7fe7aac73dd0>', 'mechanism': {'type': 'logging', 'handled': True}, 'stacktrace': {'frames': [{'filename': 'uvicorn/protocols/http/h11_impl.py', 'abs_path': '/home/user/dev/project/.venv/lib/python3.10/site-packages/uvicorn/protocols/http/h11_impl.py', 'function': 'run_asgi', 'module': 'uvicorn.protocols.http.h11_impl', 'lineno': 404, 'pre_context': ['        self.response_complete = False', '', '    # ASGI exception wrapper', '    async def run_asgi(self, app: "ASGI3Application") -> None:', '        try:'], 'context_line': '            result = await app(  # type: ignore[func-returns-value]', 'post_context': ['                self.scope, self.receive, self.send', '            )', '        except BaseException as exc:', '            msg = "Exception in ASGI application\\n"', '            self.logger.error(msg, exc_info=exc)'], 'vars': {'self': <uvicorn.protocols.http.h11_impl.RequestResponseCycle object at 0x7fe7aacc21d0>, 'app': <uvicorn.middleware.proxy_headers.ProxyHeadersMiddleware object at 0x7fe7ab0bf250>, 'exc': UnidentifiedImageError('cannot identify image file <_io.BytesIO object at 0x7fe7aac73dd0>'), 'msg': 'Exception in ASGI application\n'}}, {'filename': 'uvicorn/middleware/proxy_headers.py', 'abs_path': '/home/user/dev/project/.venv/lib/python3.10/site-packages/uvicorn/middleware/proxy_headers.py', 'function': '__call__', 'module': 'uvicorn.middleware.proxy_headers', 'lineno': 78, 'pre_context': ['                    ]', '                    host = self.get_trusted_client_host(x_forwarded_for_hosts)', '                    port = 0', '                    scope["client"] = (host, port)  # type: ignore[arg-type]', ''], 'context_line': '        return await self.app(scope, receive, send)', 'post_context': [], 'vars': {'self': <uvicorn.middleware.proxy_headers.ProxyHeadersMiddleware object at 0x7fe7ab0bf250>, 'scope': {'type': 'http', 'asgi': {'version': '3.0', 'spec_version': '2.3'}, 'http_version': '1.1', 'server': ('127.0.0.1', 8888), 'client': ('127.0.0.1', 36646), 'scheme': 'http', 'method': 'POST', 'root_path': '', 'path': '/predict', 'raw_path': b'/predict', 'query_string': b'', 'headers': [(b'host', b'0.0.0.0:8888'), (b'user-agent', b'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:105.0) Gecko/20100101 Firefox/105.0'), (b'accept', b'application/json'), (b'accept-language', b'en-US,en;q=0.5'), (b'accept-encoding', b'gzip, deflate'), (b'referer', b'http://0.0.0.0:8888/docs'), (b'content-type', b'multipart/form-data; boundary=---------------------------400380566414049627562207609787'), (b'content-length', b'5032'), (b'origin', b'http://0.0.0.0:8888'), (b'dnt', b'1'), (b'connection', b'keep-alive')], 'app': <fastapi.applications.FastAPI object at 0x7fe7ae877fd0>, 'fastapi_astack': <contextlib.AsyncExitStack object at 0x7fe7aacc1930>, 'router': <fastapi.routing.APIRouter object at 0x7fe7ab0906d0>, 'endpoint': <function predict at 0x7fe7ab0c7880>, 'path_params': {}, 'route': <fastapi.routing.APIRoute object at 0x7fe7ab0be620>}, 'receive': <bound method RequestResponseCycle.receive of <uvicorn.protocols.http.h11_impl.RequestResponseCycle object at 0x7fe7aacc21d0>>, 'send': <bound method RequestResponseCycle.send of <uvicorn.protocols.http.h11_impl.RequestResponseCycle object at 0x7fe7aacc21d0>>, 'client_addr': ('127.0.0.1', 36646), 'client_host': '127.0.0.1', 'headers': {b'host': b'0.0.0.0:8888', b'user-agent': b'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:105.0) Gecko/20100101 Firefox/105.0', b'accept': b'application/json', b'accept-language': b'en-US,en;q=0.5', b'accept-encoding': b'gzip, deflate', b'referer': b'http://0.0.0.0:8888/docs', b'content-type': b'multipart/form-data; boundary=---------------------------400380566414049627562207609787', b'content-length': b'5032', b'origin': b'http://0.0.0.0:8888', b'dnt': b'1', b'connection': b'keep-alive'}}}, {'filename': 'fastapi/applications.py', 'abs_path': '/home/user/dev/project/.venv/lib/python3.10/site-packages/fastapi/applications.py', 'function': '__call__', 'module': 'fastapi.applications', 'lineno': 269, 'pre_context': ['            self.add_route(self.redoc_url, redoc_html, include_in_schema=False)', '', '    async def __call__(self, scope: Scope, receive: Receive, send: Send) -> None:', '        if self.root_path:', '            scope["root_path"] = self.root_path'], 'context_line': '        await super().__call__(scope, receive, send)', 'post_context': ['', '    def add_api_route(', '        self,', '        path: str,', '        endpoint: Callable[..., Coroutine[Any, Any, Response]],'], 'vars': {'self': <fastapi.applications.FastAPI object at 0x7fe7ae877fd0>, 'scope': {'type': 'http', 'asgi': {'version': '3.0', 'spec_version': '2.3'}, 'http_version': '1.1', 'server': ('127.0.0.1', 8888), 'client': ('127.0.0.1', 36646), 'scheme': 'http', 'method': 'POST', 'root_path': '', 'path': '/predict', 'raw_path': b'/predict', 'query_string': b'', 'headers': [(b'host', b'0.0.0.0:8888'), (b'user-agent', b'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:105.0) Gecko/20100101 Firefox/105.0'), (b'accept', b'application/json'), (b'accept-language', b'en-US,en;q=0.5'), (b'accept-encoding', b'gzip, deflate'), (b'referer', b'http://0.0.0.0:8888/docs'), (b'content-type', b'multipart/form-data; boundary=---------------------------400380566414049627562207609787'), (b'content-length', b'5032'), (b'origin', b'http://0.0.0.0:8888'), (b'dnt', b'1'), (b'connection', b'keep-alive')], 'app': <fastapi.applications.FastAPI object at 0x7fe7ae877fd0>, 'fastapi_astack': <contextlib.AsyncExitStack object at 0x7fe7aacc1930>, 'router': <fastapi.routing.APIRouter object at 0x7fe7ab0906d0>, 'endpoint': <function predict at 0x7fe7ab0c7880>, 'path_params': {}, 'route': <fastapi.routing.APIRoute object at 0x7fe7ab0be620>}, 'receive': <bound method RequestResponseCycle.receive of <uvicorn.protocols.http.h11_impl.RequestResponseCycle object at 0x7fe7aacc21d0>>, 'send': <bound method RequestResponseCycle.send of <uvicorn.protocols.http.h11_impl.RequestResponseCycle object at 0x7fe7aacc21d0>>, '__class__': <class 'fastapi.applications.FastAPI'>}}, {'filename': 'starlette/applications.py', 'abs_path': '/home/user/dev/project/.venv/lib/python3.10/site-packages/starlette/applications.py', 'function': '__call__', 'module': 'starlette.applications', 'lineno': 124, 'pre_context': ['    def url_path_for(self, name: str, **path_params: typing.Any) -> URLPath:', '        return self.router.url_path_for(name, **path_params)', '', '    async def __call__(self, scope: Scope, receive: Receive, send: Send) -> None:', '        scope["app"] = self'], 'context_line': '        await self.middleware_stack(scope, receive, send)', 'post_context': ['', '    # The following usages are now discouraged in favour of configuration', '    # during Starlette.__init__(...)', '    def on_event(self, event_type: str) -> typing.Callable:  # pragma: nocover', '        return self.router.on_event(event_type)'], 'vars': {'self': <fastapi.applications.FastAPI object at 0x7fe7ae877fd0>, 'scope': {'type': 'http', 'asgi': {'version': '3.0', 'spec_version': '2.3'}, 'http_version': '1.1', 'server': ('127.0.0.1', 8888), 'client': ('127.0.0.1', 36646), 'scheme': 'http', 'method': 'POST', 'root_path': '', 'path': '/predict', 'raw_path': b'/predict', 'query_string': b'', 'headers': [(b'host', b'0.0.0.0:8888'), (b'user-agent', b'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:105.0) Gecko/20100101 Firefox/105.0'), (b'accept', b'application/json'), (b'accept-language', b'en-US,en;q=0.5'), (b'accept-encoding', b'gzip, deflate'), (b'referer', b'http://0.0.0.0:8888/docs'), (b'content-type', b'multipart/form-data; boundary=---------------------------400380566414049627562207609787'), (b'content-length', b'5032'), (b'origin', b'http://0.0.0.0:8888'), (b'dnt', b'1'), (b'connection', b'keep-alive')], 'app': <fastapi.applications.FastAPI object at 0x7fe7ae877fd0>, 'fastapi_astack': <contextlib.AsyncExitStack object at 0x7fe7aacc1930>, 'router': <fastapi.routing.APIRouter object at 0x7fe7ab0906d0>, 'endpoint': <function predict at 0x7fe7ab0c7880>, 'path_params': {}, 'route': <fastapi.routing.APIRoute object at 0x7fe7ab0be620>}, 'receive': <bound method RequestResponseCycle.receive of <uvicorn.protocols.http.h11_impl.RequestResponseCycle object at 0x7fe7aacc21d0>>, 'send': <bound method RequestResponseCycle.send of <uvicorn.protocols.http.h11_impl.RequestResponseCycle object at 0x7fe7aacc21d0>>}}, {'filename': 'starlette/middleware/errors.py', 'abs_path': '/home/user/dev/project/.venv/lib/python3.10/site-packages/starlette/middleware/errors.py', 'function': '__call__', 'module': 'starlette.middleware.errors', 'lineno': 184, 'pre_context': ['                await response(scope, receive, send)', '', '            # We always continue to raise the exception.', '            # This allows servers to log the error, or allows test clients', '            # to optionally raise the error within the test case.'], 'context_line': '            raise exc', 'post_context': ['', '    def format_line(', '        self, index: int, line: str, frame_lineno: int, frame_index: int', '    ) -> str:', '        values = {'], 'vars': {'self': <starlette.middleware.errors.ServerErrorMiddleware object at 0x7fe7ab0bdcf0>, 'scope': {'type': 'http', 'asgi': {'version': '3.0', 'spec_version': '2.3'}, 'http_version': '1.1', 'server': ('127.0.0.1', 8888), 'client': ('127.0.0.1', 36646), 'scheme': 'http', 'method': 'POST', 'root_path': '', 'path': '/predict', 'raw_path': b'/predict', 'query_string': b'', 'headers': [(b'host', b'0.0.0.0:8888'), (b'user-agent', b'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:105.0) Gecko/20100101 Firefox/105.0'), (b'accept', b'application/json'), (b'accept-language', b'en-US,en;q=0.5'), (b'accept-encoding', b'gzip, deflate'), (b'referer', b'http://0.0.0.0:8888/docs'), (b'content-type', b'multipart/form-data; boundary=---------------------------400380566414049627562207609787'), (b'content-length', b'5032'), (b'origin', b'http://0.0.0.0:8888'), (b'dnt', b'1'), (b'connection', b'keep-alive')], 'app': <fastapi.applications.FastAPI object at 0x7fe7ae877fd0>, 'fastapi_astack': <contextlib.AsyncExitStack object at 0x7fe7aacc1930>, 'router': <fastapi.routing.APIRouter object at 0x7fe7ab0906d0>, 'endpoint': <function predict at 0x7fe7ab0c7880>, 'path_params': {}, 'route': <fastapi.routing.APIRoute object at 0x7fe7ab0be620>}, 'receive': <bound method RequestResponseCycle.receive of <uvicorn.protocols.http.h11_impl.RequestResponseCycle object at 0x7fe7aacc21d0>>, '_send': <function ServerErrorMiddleware.__call__.<locals>._send at 0x7fe7aacc9ab0>, 'request': <starlette.requests.Request object at 0x7fe7aacc10f0>, 'response': <starlette.responses.PlainTextResponse object at 0x7fe7aac8fac0>, 'response_started': False, 'send': <bound method RequestResponseCycle.send of <uvicorn.protocols.http.h11_impl.RequestResponseCycle object at 0x7fe7aacc21d0>>}}, {'filename': 'starlette/middleware/errors.py', 'abs_path': '/home/user/dev/project/.venv/lib/python3.10/site-packages/starlette/middleware/errors.py', 'function': '__call__', 'module': 'starlette.middleware.errors', 'lineno': 162, 'pre_context': ['            if message["type"] == "http.response.start":', '                response_started = True', '            await send(message)', '', '        try:'], 'context_line': '            await self.app(scope, receive, _send)', 'post_context': ['        except Exception as exc:', '            request = Request(scope)', '            if self.debug:', '                # In debug mode, return traceback responses.', '                response = self.debug_response(request, exc)'], 'vars': {'self': <starlette.middleware.errors.ServerErrorMiddleware object at 0x7fe7ab0bdcf0>, 'scope': {'type': 'http', 'asgi': {'version': '3.0', 'spec_version': '2.3'}, 'http_version': '1.1', 'server': ('127.0.0.1', 8888), 'client': ('127.0.0.1', 36646), 'scheme': 'http', 'method': 'POST', 'root_path': '', 'path': '/predict', 'raw_path': b'/predict', 'query_string': b'', 'headers': [(b'host', b'0.0.0.0:8888'), (b'user-agent', b'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:105.0) Gecko/20100101 Firefox/105.0'), (b'accept', b'application/json'), (b'accept-language', b'en-US,en;q=0.5'), (b'accept-encoding', b'gzip, deflate'), (b'referer', b'http://0.0.0.0:8888/docs'), (b'content-type', b'multipart/form-data; boundary=---------------------------400380566414049627562207609787'), (b'content-length', b'5032'), (b'origin', b'http://0.0.0.0:8888'), (b'dnt', b'1'), (b'connection', b'keep-alive')], 'app': <fastapi.applications.FastAPI object at 0x7fe7ae877fd0>, 'fastapi_astack': <contextlib.AsyncExitStack object at 0x7fe7aacc1930>, 'router': <fastapi.routing.APIRouter object at 0x7fe7ab0906d0>, 'endpoint': <function predict at 0x7fe7ab0c7880>, 'path_params': {}, 'route': <fastapi.routing.APIRoute object at 0x7fe7ab0be620>}, 'receive': <bound method RequestResponseCycle.receive of <uvicorn.protocols.http.h11_impl.RequestResponseCycle object at 0x7fe7aacc21d0>>, '_send': <function ServerErrorMiddleware.__call__.<locals>._send at 0x7fe7aacc9ab0>, 'request': <starlette.requests.Request object at 0x7fe7aacc10f0>, 'response': <starlette.responses.PlainTextResponse object at 0x7fe7aac8fac0>, 'response_started': False, 'send': <bound method RequestResponseCycle.send of <uvicorn.protocols.http.h11_impl.RequestResponseCycle object at 0x7fe7aacc21d0>>}}, {'filename': 'starlette/exceptions.py', 'abs_path': '/home/user/dev/project/.venv/lib/python3.10/site-packages/starlette/exceptions.py', 'function': '__call__', 'module': 'starlette.exceptions', 'lineno': 93, 'pre_context': ['', '            if handler is None:', '                handler = self._lookup_exception_handler(exc)', '', '            if handler is None:'], 'context_line': '                raise exc', 'post_context': ['', '            if response_started:', '                msg = "Caught handled exception, but response already started."', '                raise RuntimeError(msg) from exc', ''], 'vars': {'self': <starlette.exceptions.ExceptionMiddleware object at 0x7fe7ab0bdcc0>, 'scope': {'type': 'http', 'asgi': {'version': '3.0', 'spec_version': '2.3'}, 'http_version': '1.1', 'server': ('127.0.0.1', 8888), 'client': ('127.0.0.1', 36646), 'scheme': 'http', 'method': 'POST', 'root_path': '', 'path': '/predict', 'raw_path': b'/predict', 'query_string': b'', 'headers': [(b'host', b'0.0.0.0:8888'), (b'user-agent', b'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:105.0) Gecko/20100101 Firefox/105.0'), (b'accept', b'application/json'), (b'accept-language', b'en-US,en;q=0.5'), (b'accept-encoding', b'gzip, deflate'), (b'referer', b'http://0.0.0.0:8888/docs'), (b'content-type', b'multipart/form-data; boundary=---------------------------400380566414049627562207609787'), (b'content-length', b'5032'), (b'origin', b'http://0.0.0.0:8888'), (b'dnt', b'1'), (b'connection', b'keep-alive')], 'app': <fastapi.applications.FastAPI object at 0x7fe7ae877fd0>, 'fastapi_astack': <contextlib.AsyncExitStack object at 0x7fe7aacc1930>, 'router': <fastapi.routing.APIRouter object at 0x7fe7ab0906d0>, 'endpoint': <function predict at 0x7fe7ab0c7880>, 'path_params': {}, 'route': <fastapi.routing.APIRoute object at 0x7fe7ab0be620>}, 'receive': <bound method RequestResponseCycle.receive of <uvicorn.protocols.http.h11_impl.RequestResponseCycle object at 0x7fe7aacc21d0>>, 'sender': <function ExceptionMiddleware.__call__.<locals>.sender at 0x7fe7aacc9d80>, 'handler': None, 'response_started': False, 'send': <function ServerErrorMiddleware.__call__.<locals>._send at 0x7fe7aacc9ab0>}}, {'filename': 'starlette/exceptions.py', 'abs_path': '/home/user/dev/project/.venv/lib/python3.10/site-packages/starlette/exceptions.py', 'function': '__call__', 'module': 'starlette.exceptions', 'lineno': 82, 'pre_context': ['            if message["type"] == "http.response.start":', '                response_started = True', '            await send(message)', '', '        try:'], 'context_line': '            await self.app(scope, receive, sender)', 'post_context': ['        except Exception as exc:', '            handler = None', '', '            if isinstance(exc, HTTPException):', '                handler = self._status_handlers.get(exc.status_code)'], 'vars': {'self': <starlette.exceptions.ExceptionMiddleware object at 0x7fe7ab0bdcc0>, 'scope': {'type': 'http', 'asgi': {'version': '3.0', 'spec_version': '2.3'}, 'http_version': '1.1', 'server': ('127.0.0.1', 8888), 'client': ('127.0.0.1', 36646), 'scheme': 'http', 'method': 'POST', 'root_path': '', 'path': '/predict', 'raw_path': b'/predict', 'query_string': b'', 'headers': [(b'host', b'0.0.0.0:8888'), (b'user-agent', b'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:105.0) Gecko/20100101 Firefox/105.0'), (b'accept', b'application/json'), (b'accept-language', b'en-US,en;q=0.5'), (b'accept-encoding', b'gzip, deflate'), (b'referer', b'http://0.0.0.0:8888/docs'), (b'content-type', b'multipart/form-data; boundary=---------------------------400380566414049627562207609787'), (b'content-length', b'5032'), (b'origin', b'http://0.0.0.0:8888'), (b'dnt', b'1'), (b'connection', b'keep-alive')], 'app': <fastapi.applications.FastAPI object at 0x7fe7ae877fd0>, 'fastapi_astack': <contextlib.AsyncExitStack object at 0x7fe7aacc1930>, 'router': <fastapi.routing.APIRouter object at 0x7fe7ab0906d0>, 'endpoint': <function predict at 0x7fe7ab0c7880>, 'path_params': {}, 'route': <fastapi.routing.APIRoute object at 0x7fe7ab0be620>}, 'receive': <bound method RequestResponseCycle.receive of <uvicorn.protocols.http.h11_impl.RequestResponseCycle object at 0x7fe7aacc21d0>>, 'sender': <function ExceptionMiddleware.__call__.<locals>.sender at 0x7fe7aacc9d80>, 'handler': None, 'response_started': False, 'send': <function ServerErrorMiddleware.__call__.<locals>._send at 0x7fe7aacc9ab0>}}, {'filename': 'fastapi/middleware/asyncexitstack.py', 'abs_path': '/home/user/dev/project/.venv/lib/python3.10/site-packages/fastapi/middleware/asyncexitstack.py', 'function': '__call__', 'module': 'fastapi.middleware.asyncexitstack', 'lineno': 21, 'pre_context': ['                scope[self.context_name] = stack', '                try:', '                    await self.app(scope, receive, send)', '                except Exception as e:', '                    dependency_exception = e'], 'context_line': '                    raise e', 'post_context': ['            if dependency_exception:', '                # This exception was possibly handled by the dependency but it should', '                # still bubble up so that the ServerErrorMiddleware can return a 500', '                # or the ExceptionMiddleware can catch and handle any other exceptions', '                raise dependency_exception'], 'vars': {'self': <fastapi.middleware.asyncexitstack.AsyncExitStackMiddleware object at 0x7fe7ab0bdc60>, 'scope': {'type': 'http', 'asgi': {'version': '3.0', 'spec_version': '2.3'}, 'http_version': '1.1', 'server': ('127.0.0.1', 8888), 'client': ('127.0.0.1', 36646), 'scheme': 'http', 'method': 'POST', 'root_path': '', 'path': '/predict', 'raw_path': b'/predict', 'query_string': b'', 'headers': [(b'host', b'0.0.0.0:8888'), (b'user-agent', b'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:105.0) Gecko/20100101 Firefox/105.0'), (b'accept', b'application/json'), (b'accept-language', b'en-US,en;q=0.5'), (b'accept-encoding', b'gzip, deflate'), (b'referer', b'http://0.0.0.0:8888/docs'), (b'content-type', b'multipart/form-data; boundary=---------------------------400380566414049627562207609787'), (b'content-length', b'5032'), (b'origin', b'http://0.0.0.0:8888'), (b'dnt', b'1'), (b'connection', b'keep-alive')], 'app': <fastapi.applications.FastAPI object at 0x7fe7ae877fd0>, 'fastapi_astack': <contextlib.AsyncExitStack object at 0x7fe7aacc1930>, 'router': <fastapi.routing.APIRouter object at 0x7fe7ab0906d0>, 'endpoint': <function predict at 0x7fe7ab0c7880>, 'path_params': {}, 'route': <fastapi.routing.APIRoute object at 0x7fe7ab0be620>}, 'receive': <bound method RequestResponseCycle.receive of <uvicorn.protocols.http.h11_impl.RequestResponseCycle object at 0x7fe7aacc21d0>>, 'send': <function ExceptionMiddleware.__call__.<locals>.sender at 0x7fe7aacc9d80>, 'dependency_exception': UnidentifiedImageError('cannot identify image file <_io.BytesIO object at 0x7fe7aac73dd0>'), 'stack': <contextlib.AsyncExitStack object at 0x7fe7aacc1930>}}, {'filename': 'fastapi/middleware/asyncexitstack.py', 'abs_path': '/home/user/dev/project/.venv/lib/python3.10/site-packages/fastapi/middleware/asyncexitstack.py', 'function': '__call__', 'module': 'fastapi.middleware.asyncexitstack', 'lineno': 18, 'pre_context': ['        if AsyncExitStack:', '            dependency_exception: Optional[Exception] = None', '            async with AsyncExitStack() as stack:', '                scope[self.context_name] = stack', '                try:'], 'context_line': '                    await self.app(scope, receive, send)', 'post_context': ['                except Exception as e:', '                    dependency_exception = e', '                    raise e', '            if dependency_exception:', '                # This exception was possibly handled by the dependency but it should'], 'vars': {'self': <fastapi.middleware.asyncexitstack.AsyncExitStackMiddleware object at 0x7fe7ab0bdc60>, 'scope': {'type': 'http', 'asgi': {'version': '3.0', 'spec_version': '2.3'}, 'http_version': '1.1', 'server': ('127.0.0.1', 8888), 'client': ('127.0.0.1', 36646), 'scheme': 'http', 'method': 'POST', 'root_path': '', 'path': '/predict', 'raw_path': b'/predict', 'query_string': b'', 'headers': [(b'host', b'0.0.0.0:8888'), (b'user-agent', b'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:105.0) Gecko/20100101 Firefox/105.0'), (b'accept', b'application/json'), (b'accept-language', b'en-US,en;q=0.5'), (b'accept-encoding', b'gzip, deflate'), (b'referer', b'http://0.0.0.0:8888/docs'), (b'content-type', b'multipart/form-data; boundary=---------------------------400380566414049627562207609787'), (b'content-length', b'5032'), (b'origin', b'http://0.0.0.0:8888'), (b'dnt', b'1'), (b'connection', b'keep-alive')], 'app': <fastapi.applications.FastAPI object at 0x7fe7ae877fd0>, 'fastapi_astack': <contextlib.AsyncExitStack object at 0x7fe7aacc1930>, 'router': <fastapi.routing.APIRouter object at 0x7fe7ab0906d0>, 'endpoint': <function predict at 0x7fe7ab0c7880>, 'path_params': {}, 'route': <fastapi.routing.APIRoute object at 0x7fe7ab0be620>}, 'receive': <bound method RequestResponseCycle.receive of <uvicorn.protocols.http.h11_impl.RequestResponseCycle object at 0x7fe7aacc21d0>>, 'send': <function ExceptionMiddleware.__call__.<locals>.sender at 0x7fe7aacc9d80>, 'dependency_exception': UnidentifiedImageError('cannot identify image file <_io.BytesIO object at 0x7fe7aac73dd0>'), 'stack': <contextlib.AsyncExitStack object at 0x7fe7aacc1930>}}, {'filename': 'starlette/routing.py', 'abs_path': '/home/user/dev/project/.venv/lib/python3.10/site-packages/starlette/routing.py', 'function': '__call__', 'module': 'starlette.routing', 'lineno': 670, 'pre_context': ['            # Determine if any route matches the incoming scope,', '            # and hand over to the matching route if found.', '            match, child_scope = route.matches(scope)', '            if match == Match.FULL:', '                scope.update(child_scope)'], 'context_line': '                await route.handle(scope, receive, send)', 'post_context': ['                return', '            elif match == Match.PARTIAL and partial is None:', '                partial = route', '                partial_scope = child_scope', ''], 'vars': {'self': <fastapi.routing.APIRouter object at 0x7fe7ab0906d0>, 'scope': {'type': 'http', 'asgi': {'version': '3.0', 'spec_version': '2.3'}, 'http_version': '1.1', 'server': ('127.0.0.1', 8888), 'client': ('127.0.0.1', 36646), 'scheme': 'http', 'method': 'POST', 'root_path': '', 'path': '/predict', 'raw_path': b'/predict', 'query_string': b'', 'headers': [(b'host', b'0.0.0.0:8888'), (b'user-agent', b'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:105.0) Gecko/20100101 Firefox/105.0'), (b'accept', b'application/json'), (b'accept-language', b'en-US,en;q=0.5'), (b'accept-encoding', b'gzip, deflate'), (b'referer', b'http://0.0.0.0:8888/docs'), (b'content-type', b'multipart/form-data; boundary=---------------------------400380566414049627562207609787'), (b'content-length', b'5032'), (b'origin', b'http://0.0.0.0:8888'), (b'dnt', b'1'), (b'connection', b'keep-alive')], 'app': <fastapi.applications.FastAPI object at 0x7fe7ae877fd0>, 'fastapi_astack': <contextlib.AsyncExitStack object at 0x7fe7aacc1930>, 'router': <fastapi.routing.APIRouter object at 0x7fe7ab0906d0>, 'endpoint': <function predict at 0x7fe7ab0c7880>, 'path_params': {}, 'route': <fastapi.routing.APIRoute object at 0x7fe7ab0be620>}, 'receive': <bound method RequestResponseCycle.receive of <uvicorn.protocols.http.h11_impl.RequestResponseCycle object at 0x7fe7aacc21d0>>, 'send': <function ExceptionMiddleware.__call__.<locals>.sender at 0x7fe7aacc9d80>, 'partial': None, 'route': <fastapi.routing.APIRoute object at 0x7fe7ab0be620>, 'match': <Match.FULL: 2>, 'child_scope': {'endpoint': <function predict at 0x7fe7ab0c7880>, 'path_params': {}, 'route': <fastapi.routing.APIRoute object at 0x7fe7ab0be620>}}}, {'filename': 'starlette/routing.py', 'abs_path': '/home/user/dev/project/.venv/lib/python3.10/site-packages/starlette/routing.py', 'function': 'handle', 'module': 'starlette.routing', 'lineno': 266, 'pre_context': ['                response = PlainTextResponse(', '                    "Method Not Allowed", status_code=405, headers=headers', '                )', '            await response(scope, receive, send)', '        else:'], 'context_line': '            await self.app(scope, receive, send)', 'post_context': ['', '    def __eq__(self, other: typing.Any) -> bool:', '        return (', '            isinstance(other, Route)', '            and self.path == other.path'], 'vars': {'self': <fastapi.routing.APIRoute object at 0x7fe7ab0be620>, 'scope': {'type': 'http', 'asgi': {'version': '3.0', 'spec_version': '2.3'}, 'http_version': '1.1', 'server': ('127.0.0.1', 8888), 'client': ('127.0.0.1', 36646), 'scheme': 'http', 'method': 'POST', 'root_path': '', 'path': '/predict', 'raw_path': b'/predict', 'query_string': b'', 'headers': [(b'host', b'0.0.0.0:8888'), (b'user-agent', b'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:105.0) Gecko/20100101 Firefox/105.0'), (b'accept', b'application/json'), (b'accept-language', b'en-US,en;q=0.5'), (b'accept-encoding', b'gzip, deflate'), (b'referer', b'http://0.0.0.0:8888/docs'), (b'content-type', b'multipart/form-data; boundary=---------------------------400380566414049627562207609787'), (b'content-length', b'5032'), (b'origin', b'http://0.0.0.0:8888'), (b'dnt', b'1'), (b'connection', b'keep-alive')], 'app': <fastapi.applications.FastAPI object at 0x7fe7ae877fd0>, 'fastapi_astack': <contextlib.AsyncExitStack object at 0x7fe7aacc1930>, 'router': <fastapi.routing.APIRouter object at 0x7fe7ab0906d0>, 'endpoint': <function predict at 0x7fe7ab0c7880>, 'path_params': {}, 'route': <fastapi.routing.APIRoute object at 0x7fe7ab0be620>}, 'receive': <bound method RequestResponseCycle.receive of <uvicorn.protocols.http.h11_impl.RequestResponseCycle object at 0x7fe7aacc21d0>>, 'send': <function ExceptionMiddleware.__call__.<locals>.sender at 0x7fe7aacc9d80>}}, {'filename': 'starlette/routing.py', 'abs_path': '/home/user/dev/project/.venv/lib/python3.10/site-packages/starlette/routing.py', 'function': 'app', 'module': 'starlette.routing', 'lineno': 65, 'pre_context': ['    is_coroutine = iscoroutinefunction_or_partial(func)', '', '    async def app(scope: Scope, receive: Receive, send: Send) -> None:', '        request = Request(scope, receive=receive, send=send)', '        if is_coroutine:'], 'context_line': '            response = await func(request)', 'post_context': ['        else:', '            response = await run_in_threadpool(func, request)', '        await response(scope, receive, send)', '', '    return app'], 'vars': {'scope': {'type': 'http', 'asgi': {'version': '3.0', 'spec_version': '2.3'}, 'http_version': '1.1', 'server': ('127.0.0.1', 8888), 'client': ('127.0.0.1', 36646), 'scheme': 'http', 'method': 'POST', 'root_path': '', 'path': '/predict', 'raw_path': b'/predict', 'query_string': b'', 'headers': [(b'host', b'0.0.0.0:8888'), (b'user-agent', b'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:105.0) Gecko/20100101 Firefox/105.0'), (b'accept', b'application/json'), (b'accept-language', b'en-US,en;q=0.5'), (b'accept-encoding', b'gzip, deflate'), (b'referer', b'http://0.0.0.0:8888/docs'), (b'content-type', b'multipart/form-data; boundary=---------------------------400380566414049627562207609787'), (b'content-length', b'5032'), (b'origin', b'http://0.0.0.0:8888'), (b'dnt', b'1'), (b'connection', b'keep-alive')], 'app': <fastapi.applications.FastAPI object at 0x7fe7ae877fd0>, 'fastapi_astack': <contextlib.AsyncExitStack object at 0x7fe7aacc1930>, 'router': <fastapi.routing.APIRouter object at 0x7fe7ab0906d0>, 'endpoint': <function predict at 0x7fe7ab0c7880>, 'path_params': {}, 'route': <fastapi.routing.APIRoute object at 0x7fe7ab0be620>}, 'receive': <bound method RequestResponseCycle.receive of <uvicorn.protocols.http.h11_impl.RequestResponseCycle object at 0x7fe7aacc21d0>>, 'send': <function ExceptionMiddleware.__call__.<locals>.sender at 0x7fe7aacc9d80>, 'request': <starlette.requests.Request object at 0x7fe7aacc1150>, 'func': <function patch_get_request_handler.<locals>._sentry_get_request_handler.<locals>._sentry_app at 0x7fe7ab0c79a0>, 'is_coroutine': True}}, {'filename': 'fastapi/routing.py', 'abs_path': '/home/user/dev/project/.venv/lib/python3.10/site-packages/fastapi/routing.py', 'function': 'app', 'module': 'fastapi.routing', 'lineno': 231, 'pre_context': ['        )', '        values, errors, background_tasks, sub_response, _ = solved_result', '        if errors:', '            raise RequestValidationError(errors, body=body)', '        else:'], 'context_line': '            raw_response = await run_endpoint_function(', 'post_context': ['                dependant=dependant, values=values, is_coroutine=is_coroutine', '            )', '', '            if isinstance(raw_response, Response):', '                if raw_response.background is None:'], 'vars': {'request': <starlette.requests.Request object at 0x7fe7aacc1150>, 'body': FormData([('file', <starlette.datastructures.UploadFile object at 0x7fe7aacc1ae0>)]), 'solved_result': ({'file': <starlette.datastructures.UploadFile object at 0x7fe7aacc1ae0>}, [], None, <starlette.responses.Response object at 0x7fe7aacc2830>, {}), 'values': {'file': <starlette.datastructures.UploadFile object at 0x7fe7aacc1ae0>}, 'errors': [], 'background_tasks': None, 'sub_response': <starlette.responses.Response object at 0x7fe7aacc2830>, '_': {}, 'actual_response_class': <class 'starlette.responses.JSONResponse'>, 'body_field': ModelField(name='body', type=Optional[Body_predict_predict_post], required=False, default=None), 'dependant': <fastapi.dependencies.models.Dependant object at 0x7fe7ab0be6e0>, 'dependency_overrides_provider': <fastapi.applications.FastAPI object at 0x7fe7ae877fd0>, 'is_body_form': True, 'is_coroutine': True, 'response_field': None, 'response_model_by_alias': True, 'response_model_exclude': None, 'response_model_exclude_defaults': False, 'response_model_exclude_none': False, 'response_model_exclude_unset': False, 'response_model_include': None, 'status_code': None}}, {'filename': 'fastapi/routing.py', 'abs_path': '/home/user/dev/project/.venv/lib/python3.10/site-packages/fastapi/routing.py', 'function': 'run_endpoint_function', 'module': 'fastapi.routing', 'lineno': 160, 'pre_context': ['    # Only called by get_request_handler. Has been split into its own function to', '    # facilitate profiling endpoints, since inner functions are harder to profile.', '    assert dependant.call is not None, "dependant.call must be a function"', '', '    if is_coroutine:'], 'context_line': '        return await dependant.call(**values)', 'post_context': ['    else:', '        return await run_in_threadpool(dependant.call, **values)', '', '', 'def get_request_handler('], 'vars': {'dependant': <fastapi.dependencies.models.Dependant object at 0x7fe7ab0be6e0>, 'values': {'file': <starlette.datastructures.UploadFile object at 0x7fe7aacc1ae0>}, 'is_coroutine': True}}, {'filename': '_check_sentry.py', 'abs_path': '/home/user/dev/project/_check_sentry.py', 'function': 'predict', 'module': '__main__', 'lineno': 20, 'pre_context': ['', '', '@app.post("/predict")', 'async def predict(file: UploadFile = File(default=None)):', '    contents = await file.read()'], 'context_line': '    Image.open(io.BytesIO(contents)).convert("RGB")', 'post_context': ['    return {"result": "ok"}', '', "if __name__ == '__main__':", '    uvicorn.run(app, host="0.0.0.0", port=8888, loop="asyncio", lifespan="on")'], 'vars': {'file': <starlette.datastructures.UploadFile object at 0x7fe7aacc1ae0>, 'contents': b''}}, {'filename': 'PIL/Image.py', 'abs_path': '/home/user/dev/project/.venv/lib/python3.10/site-packages/PIL/Image.py', 'function': 'open', 'module': 'PIL.Image', 'lineno': 3147, 'pre_context': ['', '    if exclusive_fp:', '        fp.close()', '    for message in accept_warnings:', '        warnings.warn(message)'], 'context_line': '    raise UnidentifiedImageError(', 'post_context': ['        "cannot identify image file %r" % (filename if filename else fp)', '    )', '', '', '#'], 'vars': {'fp': <_io.BytesIO object at 0x7fe7aac73dd0>, 'mode': 'r', 'formats': ['BMP', 'DIB', 'GIF', 'TIFF', 'JPEG', 'PPM', 'PNG', 'BLP', 'BUFR', 'CUR', 'PCX', 'DCX', 'DDS', 'EPS', 'FITS', 'FLI', 'FTEX', 'GBR', 'GRIB', 'HDF5', 'JPEG2000', 'ICNS', 'ICO', 'IM', 'IMT', 'IPTC', 'MCIDAS', 'MPEG', 'MSP', 'PCD', 'PIXAR', 'PSD', 'SGI', 'SPIDER', 'SUN', 'TGA', 'WEBP', 'WMF', 'XBM', 'XPM', 'XVTHUMB'], 'filename': '', 'prefix': b'', '_open_core': <function open.<locals>._open_core at 0x7fe7aacc9e10>, 'im': None, 'accept_warnings': [], 'exclusive_fp': False}}]}}]}, 'logger': 'uvicorn.error', 'logentry': {'message': 'Exception in ASGI application\n', 'params': ()}, 'extra': {}, 'event_id': 'fea275a649c6475ea3f2d7fc5992ea70', 'timestamp': datetime.datetime(2022, 10, 3, 8, 28, 36, 695800), 'breadcrumbs': {'values': [{'type': 'log', 'level': 'info', 'category': 'uvicorn.error', 'message': 'Started server process [15665]', 'timestamp': datetime.datetime(2022, 10, 3, 8, 28, 34, 413098), 'data': {'color_message': 'Started server process [\x1b[36m%d\x1b[0m]'}}, {'type': 'log', 'level': 'info', 'category': 'uvicorn.error', 'message': 'Waiting for application startup.', 'timestamp': datetime.datetime(2022, 10, 3, 8, 28, 34, 413872), 'data': {}}, {'type': 'log', 'level': 'info', 'category': 'uvicorn.error', 'message': 'Application startup complete.', 'timestamp': datetime.datetime(2022, 10, 3, 8, 28, 34, 491950), 'data': {}}, {'type': 'log', 'level': 'info', 'category': 'uvicorn.error', 'message': 'Uvicorn running on http://0.0.0.0:8888 (Press CTRL+C to quit)', 'timestamp': datetime.datetime(2022, 10, 3, 8, 28, 34, 492298), 'data': {'color_message': 'Uvicorn running on \x1b[1m%s://%s:%d\x1b[0m (Press CTRL+C to quit)'}}]}, 'transaction_info': {}, 'contexts': {'runtime': {'name': 'CPython', 'version': '3.10.6', 'build': '3.10.6 (main, Aug 10 2022, 11:40:04) [GCC 11.3.0]'}}})
 [sentry] DEBUG: [Tracing] Adding `sentry-trace` header 47b30a16b7ce472190e95b403cb7cb9d-8d075345720e996f- to outgoing request to https://<SECRET_HOST>/api/3/store/.
 [sentry] DEBUG: Sending envelope [envelope with 1 items (transaction)] project:3 host:<SECRET_HOST>
 [sentry] DEBUG: [Tracing] Adding `sentry-trace` header d656bb543290437e95680a6e72d4661f-92467f6e020cf8c4- to outgoing request to https://<SECRET_HOST>/api/3/envelope/.

^CINFO:     Shutting down
INFO:     Waiting for application shutdown.
INFO:     Application shutdown complete.
INFO:     Finished server process [15665]
 [sentry] DEBUG: atexit: got shutdown signal
 [sentry] DEBUG: atexit: shutting down client
 [sentry] DEBUG: Flushing HTTP transport
 [sentry] DEBUG: background worker got flush request
 [sentry] DEBUG: Sending envelope [envelope with 2 items (transaction, internal)] project:3 host:<SECRET_HOST>
 [sentry] DEBUG: [Tracing] Adding `sentry-trace` header 038bbd1fd24e4d62bf3e959cfe3bb127-b934cb9d7607f082- to outgoing request to https://<SECRET_HOST>/api/3/envelope/.
 [sentry] DEBUG: Sending envelope [envelope with 1 items (default)] project:3 host:<SECRET_HOST>
 [sentry] DEBUG: [Tracing] Adding `sentry-trace` header f4e6b6ae33fa4c1cb9ab0c85bd4e0089-994e36c4fcd6a000- to outgoing request to https://<SECRET_HOST>/api/3/envelope/.
 [sentry] DEBUG: background worker flushed
 [sentry] DEBUG: Killing HTTP transport
 [sentry] DEBUG: background worker got kill request
antonpirker commented 1 year ago

Hello!

Thanks for the debug output! This output says that there is an error in the line Image.open(io.BytesIO(contents)).convert("RGB") because the uploaded file can not be identified as an image.

Could it be that you upload a file that is not an image?

RockBomber commented 1 year ago

It's because "image" has zero bytes :) If I set await file.seek(0) the image will be processed successfully

antonpirker commented 1 year ago

Can you send me the image to anton.pirker@sentry.io so I can test?

RockBomber commented 1 year ago

You know, it's interesting.. with first random image I've got that error but with other images I don't have the error. Some "magic" image.. I'll send it to you

antonpirker commented 1 year ago

Thanks for the image. Yes, it is strange. But I guess it should be fixed with this issue: https://github.com/getsentry/sentry-python/issues/1631

We will do a release soon, then you can try again if it is finally working. Thanks for all the debugging @RockBomber !