Skip to content

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
Deadpool2000:fix-issue-9
Open

Fix issue #9: Fix 400 Bad Request on API calls containing special characters in query parameters#16
Deadpool2000 wants to merge 3 commits intoopenapi:mainfrom
Deadpool2000:fix-issue-9

Conversation

@Deadpool2000
Copy link
Copy Markdown
Contributor

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's requests), 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 a 400 Bad Request (invalid encoding) error when it attempts to parse the strict %20 format from our data pipelines.

What I did to fix it:

Rather than reverting away from httpx, I updated the core request() method in both the synchronous (Client) and asynchronous (AsyncClient) classes.

  • I intercepted the params dictionary before httpx touches it and manually pre-encoded it using Python's standard urllib.parse.urlencode().
  • I added the doseq=True flag to safely ensure any lists passed in the query are parsed correctly.
  • I then dynamically appended the generated query string directly to the URL.

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 pytest suites pass cleanly.

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 this pull request may close these issues.

1 participant