Fix issue #9: Fix 400 Bad Request on API calls containing special characters in query parameters#16
Open
Deadpool2000 wants to merge 3 commits intoopenapi:mainfrom
Open
Fix issue #9: Fix 400 Bad Request on API calls containing special characters in query parameters#16Deadpool2000 wants to merge 3 commits intoopenapi:mainfrom
Deadpool2000 wants to merge 3 commits intoopenapi:mainfrom
Conversation
…retry configurations
…quest with special characters
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.
During the recent refactor that migrated our underlying HTTP client to
httpx, we inadvertently introduced a subtle bug when passing query parameters containing special characters (like&) or spaces (like in"azienda & co").Our previous setup used
urllib-style encoding (default for Python'srequests), which encodes spaces natively as a+symbol in the URL.httpx, however, strictly adheres to RFC 3986 and encodes spaces as%20. It turns out the backend API explicitly expects standard form-style encoding (+) and throws a400 Bad Request (invalid encoding)error when it attempts to parse the strict%20format from our data pipelines.What I did to fix it:
Rather than reverting away from
httpx, I updated the corerequest()method in both the synchronous (Client) and asynchronous (AsyncClient) classes.paramsdictionary beforehttpxtouches it and manually pre-encoded it using Python's standardurllib.parse.urlencode().doseq=Trueflag to safely ensure any lists passed in the query are parsed correctly.Impact
This perfectly mirrors the encoding behavior the SDK used to have before the async refactor. Everything is strictly backward compatible: pipelines passing special characters in query params will work out of the box again, no structural or signature changes were made to the API, and all existing
pytestsuites pass cleanly.