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

fix(utils): Fix UnicodeDecodeError on Python 2 #2657

Merged
merged 9 commits into from
Jan 29, 2024
Next Next commit
Fix UnicodeDecodeError on Python 2.7
  • Loading branch information
sentrivana committed Jan 9, 2024
commit 9aa3d031feb0d84314e0d77789c7c5eb2f0dfdf7
8 changes: 7 additions & 1 deletion sentry_sdk/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -1126,7 +1126,13 @@ def strip_string(value, max_length=None):
if max_length is None:
max_length = DEFAULT_MAX_VALUE_LENGTH

length = len(value.encode("utf-8"))
length = len(value)
if isinstance(value, text_type):
# we want the size in bytes rather than characters, if possible
try:
length = len(value.encode("utf-8"))
except UnicodeDecodeError:
pass

if length > max_length:
return AnnotatedValue(
Expand Down