fix: replace ascii codec with safe UTF-8 decode for JSON responses (#1298)#1429
Draft
jayy-77 wants to merge 1 commit intoCrowdStrike:devfrom
Draft
fix: replace ascii codec with safe UTF-8 decode for JSON responses (#1298)#1429jayy-77 wants to merge 1 commit intoCrowdStrike:devfrom
jayy-77 wants to merge 1 commit intoCrowdStrike:devfrom
Conversation
…rowdStrike#1298) When the CrowdStrike API returns a JSON response containing non-ASCII characters (e.g. accented names like Ángel, Müller, François), the SDK called resp.content.decode('ascii') which crashed with: 'ascii' codec can't decode byte 0xc3 The UnicodeDecodeError propagated to the catch-all handler and was wrapped as a generic SDKError with code 500, masking the actual response data. Modified source files (5): - src/falconpy/_util/_functions.py: Add _safe_decode_content() helper that tries UTF-8 then latin-1; replace decode('ascii'); add explicit UnicodeDecodeError handler with ContentDecodingError - src/falconpy/_error/_exceptions.py: Add ContentDecodingError with encoding/position diagnostics - src/falconpy/_error/__init__.py: Export ContentDecodingError - src/falconpy/_error/_warnings.py: Add encoding property to NoContentWarning for decode failure context - src/falconpy/_result/_result.py: Add _safe_decode_body() for encoding-aware body parsing in Result construction - src/falconpy/api_complete/_legacy.py: Robust error extraction in Uber class authenticate() Tests: 28 edge-case unit tests in tests/test_ascii_decode_fix.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What is the purpose of this change?
Fixes #1298 —
'ascii' codec can't decode byte 0xc3error when the API returns JSON with non-ASCII characters (accented names like Ángel, Müller).Root cause:
calc_content_return()usedresp.content.decode("ascii")as a JSON fallback, which crashes on any byte > 127 (common in UTF-8 multi-byte sequences). TheUnicodeDecodeErrorpropagated to the catch-all handler and was masked as a generic SDKError with code 500.What does this change do?
_safe_decode_content()helper (UTF-8 → latin-1 fallback)decode("ascii")with safe decode incalc_content_return()UnicodeDecodeErrorhandler withContentDecodingErrorContentDecodingErrorexception with encoding/position diagnosticsNoContentWarning_safe_decode_body()toBaseResultfor encoding-aware parsingFiles changed (6 source + 1 test)
src/falconpy/_util/_functions.pysrc/falconpy/_error/_exceptions.pysrc/falconpy/_error/__init__.pysrc/falconpy/_error/_warnings.pysrc/falconpy/_result/_result.pysrc/falconpy/api_complete/_legacy.pytests/test_ascii_decode_fix.py(28 tests)