FastAPI file upload not working with sentry after 1.9.6
See original GitHub issueHow 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.
Issue Analytics
- State:
- Created a year ago
- Reactions:2
- Comments:13 (7 by maintainers)
Top Results From Across the Web
Request Files - FastAPI
Define File Parameters The files will be uploaded as "form data". If you declare the type of your path operation function parameter as...
Read more >sentry Changelog - PyUp.io
**Breaking Change**: This version introduces a change to the grouping of issues. The SDK now sets the `inApp` flag for frames originating from...
Read more >Python - CVE - Search Results
The problem has been patched in XWiki 14.6RC1, 13.10.8 and 14.4.3. ... This could lead to uploading python files which can be later...
Read more >How to Upload File using FastAPI? - python - Stack Overflow
I just use f = open(file) method once, and when I send the request several times, the f will be closed after the...
Read more >Source Packages in "jammy", Subsection misc - Ubuntu
Source Packages in "jammy", Subsection misc. 0xffff (0.9-1) [universe]; 1oom (1.0-2) [multiverse]; 2048 (0.20210105.1243-1) [universe] ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
with version 1.9.8 still got the error.
We managed to work around this problem for now by adding
await file.seek(0)
before theawait file.read()
call.