Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JSONDecodeError Expecting value: line 1 column 1 (char 0) (StarletteIntegration) #1550

Closed
MrSalman333 opened this issue Aug 7, 2022 · 6 comments · Fixed by #1551
Closed
Assignees

Comments

@MrSalman333
Copy link

How do you use Sentry?

Sentry Saas (sentry.io)

Version

1.9.2

Steps to Reproduce

after using the new integration we got this error some times ,, not always

 [2022-08-07 14:47:40 +0300] [11] [ERROR] Exception in ASGI application
 Traceback (most recent call last):
   File "/usr/local/lib/python3.10/site-packages/uvicorn/protocols/http/httptools_impl.py", line 401, in run_asgi
     result = await app(self.scope, self.receive, self.send)
   File "/usr/local/lib/python3.10/site-packages/sentry_sdk/integrations/starlette.py", line 98, in _create_span_call
     await old_call(*args, **kwargs)
   File "/usr/local/lib/python3.10/site-packages/uvicorn/middleware/proxy_headers.py", line 78, in __call__
     return await self.app(scope, receive, send)
   File "/usr/local/lib/python3.10/site-packages/fastapi/applications.py", line 269, in __call__
     await super().__call__(scope, receive, send)
   File "/usr/local/lib/python3.10/site-packages/sentry_sdk/integrations/starlette.py", line 287, in _sentry_patched_asgi_app
     return await middleware(scope, receive, send)
   File "/usr/local/lib/python3.10/site-packages/sentry_sdk/integrations/asgi.py", line 126, in _run_asgi3
     return await self._run_app(scope, lambda: self.app(scope, receive, send))
   File "/usr/local/lib/python3.10/site-packages/sentry_sdk/integrations/asgi.py", line 176, in _run_app
     raise exc from None
   File "/usr/local/lib/python3.10/site-packages/sentry_sdk/integrations/asgi.py", line 171, in _run_app
     return await callback()
   File "/usr/local/lib/python3.10/site-packages/starlette/applications.py", line 124, in __call__
     await self.middleware_stack(scope, receive, send)
   File "/usr/local/lib/python3.10/site-packages/sentry_sdk/integrations/starlette.py", line 98, in _create_span_call
     await old_call(*args, **kwargs)
   File "/usr/local/lib/python3.10/site-packages/starlette/middleware/errors.py", line 184, in __call__
     raise exc
   File "/usr/local/lib/python3.10/site-packages/starlette/middleware/errors.py", line 162, in __call__
     await self.app(scope, receive, _send)
   File "/usr/local/lib/python3.10/site-packages/sentry_sdk/integrations/starlette.py", line 98, in _create_span_call
     await old_call(*args, **kwargs)
   File "/usr/local/lib/python3.10/site-packages/starlette/middleware/base.py", line 68, in __call__
     response = await self.dispatch_func(request, call_next)
   File "/app/commons/main.py", line 52, in add_release_tag_custom_header
     response = await call_next(request)
   File "/usr/local/lib/python3.10/site-packages/starlette/middleware/base.py", line 46, in call_next
     raise app_exc
   File "/usr/local/lib/python3.10/site-packages/starlette/middleware/base.py", line 36, in coro
     await self.app(scope, request.receive, send_stream.send)
   File "/usr/local/lib/python3.10/site-packages/sentry_sdk/integrations/starlette.py", line 98, in _create_span_call
     await old_call(*args, **kwargs)
   File "/usr/local/lib/python3.10/site-packages/scout_apm/async_/starlette.py", line 73, in __call__
     raise exc
   File "/usr/local/lib/python3.10/site-packages/scout_apm/async_/starlette.py", line 70, in __call__
     await self.app(scope, receive, wrapped_send)
   File "/usr/local/lib/python3.10/site-packages/sentry_sdk/integrations/starlette.py", line 98, in _create_span_call
     await old_call(*args, **kwargs)
   File "/usr/local/lib/python3.10/site-packages/starlette/middleware/cors.py", line 84, in __call__
     await self.app(scope, receive, send)
   File "/usr/local/lib/python3.10/site-packages/sentry_sdk/integrations/starlette.py", line 98, in _create_span_call
     await old_call(*args, **kwargs)
   File "/usr/local/lib/python3.10/site-packages/starlette/middleware/trustedhost.py", line 34, in __call__
     await self.app(scope, receive, send)
   File "/usr/local/lib/python3.10/site-packages/sentry_sdk/integrations/starlette.py", line 98, in _create_span_call
     await old_call(*args, **kwargs)
   File "/usr/local/lib/python3.10/site-packages/uvicorn/middleware/proxy_headers.py", line 78, in __call__
     return await self.app(scope, receive, send)
   File "/usr/local/lib/python3.10/site-packages/sentry_sdk/integrations/starlette.py", line 98, in _create_span_call
     await old_call(*args, **kwargs)
   File "/usr/local/lib/python3.10/site-packages/starlette/middleware/gzip.py", line 24, in __call__
     await responder(scope, receive, send)
   File "/usr/local/lib/python3.10/site-packages/starlette/middleware/gzip.py", line 43, in __call__
     await self.app(scope, receive, self.send_with_gzip)
   File "/usr/local/lib/python3.10/site-packages/sentry_sdk/integrations/starlette.py", line 189, in _sentry_exceptionmiddleware_call
     await old_call(self, scope, receive, send)
   File "/usr/local/lib/python3.10/site-packages/sentry_sdk/integrations/starlette.py", line 189, in _sentry_exceptionmiddleware_call
     await old_call(self, scope, receive, send)
   File "/usr/local/lib/python3.10/site-packages/sentry_sdk/integrations/starlette.py", line 189, in _sentry_exceptionmiddleware_call
     await old_call(self, scope, receive, send)
   [Previous line repeated 4 more times]
   File "/usr/local/lib/python3.10/site-packages/sentry_sdk/integrations/starlette.py", line 98, in _create_span_call
     await old_call(*args, **kwargs)
   File "/usr/local/lib/python3.10/site-packages/starlette/exceptions.py", line 93, in __call__
     raise exc
   File "/usr/local/lib/python3.10/site-packages/starlette/exceptions.py", line 82, in __call__
     await self.app(scope, receive, sender)
   File "/usr/local/lib/python3.10/site-packages/sentry_sdk/integrations/starlette.py", line 98, in _create_span_call
     await old_call(*args, **kwargs)
   File "/usr/local/lib/python3.10/site-packages/fastapi/middleware/asyncexitstack.py", line 21, in __call__
     raise e
   File "/usr/local/lib/python3.10/site-packages/fastapi/middleware/asyncexitstack.py", line 18, in __call__
     await self.app(scope, receive, send)
   File "/usr/local/lib/python3.10/site-packages/starlette/routing.py", line 670, in __call__
     await route.handle(scope, receive, send)
   File "/usr/local/lib/python3.10/site-packages/starlette/routing.py", line 266, in handle
     await self.app(scope, receive, send)
   File "/usr/local/lib/python3.10/site-packages/starlette/routing.py", line 65, in app
     response = await func(request)
   File "/usr/local/lib/python3.10/site-packages/sentry_sdk/integrations/fastapi.py", line 77, in _sentry_app
     info = await extractor.extract_request_info()
   File "/usr/local/lib/python3.10/site-packages/sentry_sdk/integrations/starlette.py", line 449, in extract_request_info
     parsed_body = await self.parsed_body()
   File "/usr/local/lib/python3.10/site-packages/sentry_sdk/integrations/starlette.py", line 524, in parsed_body
     json_data = await self.json()
   File "/usr/local/lib/python3.10/site-packages/sentry_sdk/integrations/starlette.py", line 503, in json
     return await self.request.json()
   File "/usr/local/lib/python3.10/site-packages/starlette/requests.py", line 242, in json
     self._json = json.loads(body)
   File "/usr/local/lib/python3.10/json/__init__.py", line 346, in loads
     return _default_decoder.decode(s)
   File "/usr/local/lib/python3.10/json/decoder.py", line 337, in decode
     obj, end = self.raw_decode(s, idx=_w(s, 0).end())
   File "/usr/local/lib/python3.10/json/decoder.py", line 355, in raw_decode
     raise JSONDecodeError("Expecting value", s, err.value) from None
 json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

Expected Result

not causing an error

Actual Result

causing errors instead of reporting them >_<

@polina-popova
Copy link

Hi,
Have the same issue, also starts in middalware call_next(request).
Version
1.9.2

May be another one traceback will be helpfull:

192.168.65.5:36164 - "DELETE /api/admin/messages/ON_NSCHFDOPPR_ST1-3835050127-902713507-e820b96264604b1cb7865_ST1-3532076334-890130374-d9708aa5a9ff42b79267b_20220808_f0d75935-43de-446f-9808-c6eadbc39d07 HTTP/1.0" 500
[2022-08-08 06:34:48 +0000] [9] [ERROR] Exception in ASGI application
Traceback (most recent call last):
File "/usr/local/lib/python3.8/site-packages/uvicorn/protocols/http/httptools_impl.py", line 372, in run_asgi
result = await app(self.scope, self.receive, self.send)
File "/usr/local/lib/python3.8/site-packages/uvicorn/middleware/proxy_headers.py", line 75, in call
return await self.app(scope, receive, send)
File "/usr/local/lib/python3.8/site-packages/fastapi/applications.py", line 269, in call
await super().call(scope, receive, send)
File "/usr/local/lib/python3.8/site-packages/sentry_sdk/integrations/starlette.py", line 287, in _sentry_patched_asgi_app
return await middleware(scope, receive, send)
File "/usr/local/lib/python3.8/site-packages/sentry_sdk/integrations/asgi.py", line 126, in _run_asgi3
return await self._run_app(scope, lambda: self.app(scope, receive, send))
File "/usr/local/lib/python3.8/site-packages/sentry_sdk/integrations/asgi.py", line 176, in _run_app
raise exc from None
File "/usr/local/lib/python3.8/site-packages/sentry_sdk/integrations/asgi.py", line 171, in _run_app
return await callback()
File "/usr/local/lib/python3.8/site-packages/starlette/applications.py", line 124, in call
await self.middleware_stack(scope, receive, send)
File "/usr/local/lib/python3.8/site-packages/sentry_sdk/integrations/starlette.py", line 98, in _create_span_call
await old_call(*args, **kwargs)
File "/usr/local/lib/python3.8/site-packages/starlette/middleware/errors.py", line 184, in call
raise exc
File "/usr/local/lib/python3.8/site-packages/starlette/middleware/errors.py", line 162, in call
await self.app(scope, receive, _send)
File "/usr/local/lib/python3.8/site-packages/sentry_sdk/integrations/starlette.py", line 98, in _create_span_call
await old_call(*args, **kwargs)
File "/usr/local/lib/python3.8/site-packages/starlette/middleware/base.py", line 68, in call
response = await self.dispatch_func(request, call_next)
File "/app/app/middleware/edo_user_updates.py", line 24, in call
response = await call_next(request)
File "/usr/local/lib/python3.8/site-packages/starlette/middleware/base.py", line 46, in call_next
raise app_exc
File "/usr/local/lib/python3.8/site-packages/starlette/middleware/base.py", line 36, in coro
await self.app(scope, request.receive, send_stream.send)
File "/usr/local/lib/python3.8/site-packages/sentry_sdk/integrations/starlette.py", line 98, in _create_span_call
await old_call(*args, **kwargs)
File "/app/app/middleware/telemetry.py", line 78, in call
await self.app(scope, receive, wrapped_send)
File "/usr/local/lib/python3.8/site-packages/sentry_sdk/integrations/starlette.py", line 98, in _create_span_call
await old_call(*args, **kwargs)
File "/usr/local/lib/python3.8/site-packages/starlette/middleware/base.py", line 68, in call
response = await self.dispatch_func(request, call_next)
File "/app/app/api/middleware.py", line 24, in validate_sign_feature_switch
response = await call_next(request)
File "/usr/local/lib/python3.8/site-packages/starlette/middleware/base.py", line 46, in call_next
raise app_exc
File "/usr/local/lib/python3.8/site-packages/starlette/middleware/base.py", line 36, in coro
await self.app(scope, request.receive, send_stream.send)
File "/usr/local/lib/python3.8/site-packages/sentry_sdk/integrations/starlette.py", line 98, in _create_span_call
await old_call(*args, **kwargs)
File "/usr/local/lib/python3.8/site-packages/starlette/middleware/cors.py", line 84, in call
await self.app(scope, receive, send)
File "/usr/local/lib/python3.8/site-packages/sentry_sdk/integrations/starlette.py", line 189, in _sentry_exceptionmiddleware_call
await old_call(self, scope, receive, send)
File "/usr/local/lib/python3.8/site-packages/sentry_sdk/integrations/starlette.py", line 189, in _sentry_exceptionmiddleware_call
await old_call(self, scope, receive, send)
File "/usr/local/lib/python3.8/site-packages/sentry_sdk/integrations/starlette.py", line 189, in _sentry_exceptionmiddleware_call
await old_call(self, scope, receive, send)
[Previous line repeated 6 more times]
File "/usr/local/lib/python3.8/site-packages/sentry_sdk/integrations/starlette.py", line 98, in _create_span_call
await old_call(*args, **kwargs)
File "/usr/local/lib/python3.8/site-packages/starlette/exceptions.py", line 93, in call
raise exc
File "/usr/local/lib/python3.8/site-packages/starlette/exceptions.py", line 82, in call
await self.app(scope, receive, sender)
File "/usr/local/lib/python3.8/site-packages/sentry_sdk/integrations/starlette.py", line 98, in _create_span_call
await old_call(*args, **kwargs)
File "/usr/local/lib/python3.8/site-packages/fastapi/middleware/asyncexitstack.py", line 21, in call
raise e
File "/usr/local/lib/python3.8/site-packages/fastapi/middleware/asyncexitstack.py", line 18, in call
await self.app(scope, receive, send)
File "/usr/local/lib/python3.8/site-packages/starlette/routing.py", line 670, in call
await route.handle(scope, receive, send)
File "/usr/local/lib/python3.8/site-packages/starlette/routing.py", line 266, in handle
await self.app(scope, receive, send)
File "/usr/local/lib/python3.8/site-packages/starlette/routing.py", line 65, in app
response = await func(request)
File "/usr/local/lib/python3.8/site-packages/sentry_sdk/integrations/fastapi.py", line 77, in _sentry_app
info = await extractor.extract_request_info()
File "/usr/local/lib/python3.8/site-packages/sentry_sdk/integrations/starlette.py", line 449, in extract_request_info
parsed_body = await self.parsed_body()
File "/usr/local/lib/python3.8/site-packages/sentry_sdk/integrations/starlette.py", line 524, in parsed_body
json_data = await self.json()
File "/usr/local/lib/python3.8/site-packages/sentry_sdk/integrations/starlette.py", line 503, in json
return await self.request.json()
File "/usr/local/lib/python3.8/site-packages/starlette/requests.py", line 242, in json
self._json = json.loads(body)
File "/usr/local/lib/python3.8/json/init.py", line 357, in loads
return _default_decoder.decode(s)
File "/usr/local/lib/python3.8/json/decoder.py", line 337, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "/usr/local/lib/python3.8/json/decoder.py", line 355, in raw_decode
raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

@biel-michael
Copy link

biel-michael commented Aug 8, 2022

Same issue occurs to one of my applications as well. My application uses the Authorization header and the https://fastapi.tiangolo.com/tutorial/security/oauth2-jwt/ for storing access tokens and used the response.set_cookie call to store refresh token. It seems like that the new integrations have interfered with these operations, causing the authentication mechanism of the application to fail.

The stack trace similar to above is thrown when I try to execute the equivalent of https://fastapi.tiangolo.com/tutorial/security/get-current-user/:

from fastapi import Depends, FastAPI
from fastapi.security import OAuth2PasswordBearer

app = FastAPI()

oauth2_scheme = OAuth2PasswordBearer(tokenUrl="token")


@app.get("/items/")
async def read_items(token: str = Depends(oauth2_scheme)):
    # throws JSONDecodeError
    return {"token": token}

We have tried to remove all the existing middlewares but seems like that doesn't help.

Interestingly, the endpoints that did not involve the use of tokens work fine.

@sl0thentr0py
Copy link
Member

@MrSalman333 @polina-popova @biel-michael can one of you give me a curl request (with headers) where you run in to this?

@sl0thentr0py
Copy link
Member

ok nvm could repro, fix coming soon

@biel-michael
Copy link

biel-michael commented Aug 9, 2022

Glad to see that you can reproduce the issue! Is there any schedule to release this?

I saw that the proposed 1.9.3 release run is not successful. @sl0thentr0py

@sl0thentr0py
Copy link
Member

@biel-michael @polina-popova @MrSalman333 1.9.3 is now out

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants