From 217382a258432bf74579820cd34eaaf7c60ba979 Mon Sep 17 00:00:00 2001 From: Ivana Kellyer Date: Fri, 20 Sep 2024 17:04:58 +0200 Subject: [PATCH] follow the existing example --- sentry_sdk/integrations/_wsgi_common.py | 8 +++++++- sentry_sdk/integrations/django/__init__.py | 8 +------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/sentry_sdk/integrations/_wsgi_common.py b/sentry_sdk/integrations/_wsgi_common.py index 14a4c4aea4..c4f3f1c77e 100644 --- a/sentry_sdk/integrations/_wsgi_common.py +++ b/sentry_sdk/integrations/_wsgi_common.py @@ -152,7 +152,13 @@ def json(self): if not self.is_json(): return None - raw_data = self.raw_data() + try: + raw_data = self.raw_data() + except (RawPostDataException, ValueError): + # The body might have already been read, in which case this will + # fail + raw_data = None + if raw_data is None: return None diff --git a/sentry_sdk/integrations/django/__init__.py b/sentry_sdk/integrations/django/__init__.py index c212a49db0..c35eb87349 100644 --- a/sentry_sdk/integrations/django/__init__.py +++ b/sentry_sdk/integrations/django/__init__.py @@ -32,7 +32,6 @@ from django.conf import settings as django_settings from django.core import signals from django.conf import settings - from django.http.request import RawPostDataException try: from django.urls import resolve @@ -552,12 +551,7 @@ def cookies(self): def raw_data(self): # type: () -> Optional[bytes] - try: - return self.request.body - except RawPostDataException: - # We can't access the body anymore because the stream has already - # been read - return None + return self.request.body def form(self): # type: () -> QueryDict