You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
When the URL contains request parameters and the params parameter is set, the request parameters in the URL will disappear unexpectedly. #3621
Possible bugs may be raised as a "Potential Issue" discussion, feature requests may be raised as an "Ideas" discussion. We can then determine if the discussion needs to be escalated into an "Issue" or not.
This will help us ensure that the "Issues" list properly reflects ongoing or needed work on the project.
As shown in the following Python code, my expected output should be to reasonably concatenate the request parameters in params with those in the url. requests handled this part well, but httpx gave the following unexpected output:
import requests
import httpx
url = 'https://safebooru.org/index.php?page=post&s=list'
params = {
'pid': 0,
'tags': 'k-on!',
}
response = requests.get(url=url, params=params)
print(response.request.url) # As expected: https://safebooru.org/index.php?page=post&s=list&pid=0&tags=k-on%21
response = httpx.get(url=url, params=params)
print(response.request.url) # Unexpectedly, the request parameters in the URL were overridden by params: https://safebooru.org/index.php?pid=0&tags=k-on%21
If you want to avoid params getting dropped/overwritten when a URL already contains a query, you can pre-merge the query yourself with qs_codec (my Python port of the Node.js qs library) and hand httpx a fully-formed URL. This also gives you proper nested param handling (a[b][0]=...) and configurable encoding (spaces as %20 vs +, etc).
Safely merge existing URL query with new params
importhttpxfromurllib.parseimporturlsplit, urlunsplitimportqs_codecasqsbase_url="https://api.example.com/search?a=b&c=d"# already has querynew_params= {
"c": "D", # will co-exist or override per your choice below"e": "f",
"tags": ["x", "y"], # lists -> multiple entries or bracketed, as configured
}
parts=urlsplit(base_url)
# Decode existing query string into a nested dict (robust parsing, preserves duplicates)existing=query_string.decode(parts.query)
# Merge how you want (examples):# a) combine duplicates into a listfork, vinnew_params.items():
ifkinexisting:
# promote to list and appendexisting[k] = ([existing[k]] ifnotisinstance(existing[k], list) elseexisting[k]) + (vifisinstance(v, list) else [v])
else:
existing[k] =v# b) OR choose "last-wins" by just updating:# existing.update(new_params)# Re-encode exactly once (RFC 3986 = spaces as %20; switch to RFC1738 for '+')query_string=qs.encode(existing, qs.EncodeOptions(format=qs.Format.RFC3986))
final_url=urlunsplit((parts.scheme, parts.netloc, parts.path, query_string, parts.fragment))
resp=httpx.get(final_url)
This approach works today without changes to httpx: you bypass the internal params merge (the source of surprises here) and send an already-correct query string.
Activity
2513502304 commentedon Aug 5, 2025
As shown in the following Python code, my expected output should be to reasonably concatenate the request parameters in
paramswith those in theurl.requestshandled this part well, buthttpxgave the following unexpected output:My httpx version is 0.28.1
techouse commentedon Aug 28, 2025
If you want to avoid params getting dropped/overwritten when a URL already contains a query, you can pre-merge the query yourself with qs_codec (my Python port of the Node.js qs library) and hand httpx a fully-formed URL. This also gives you proper nested param handling (
a[b][0]=...) and configurable encoding (spaces as%20vs+, etc).Safely merge existing URL query with new params
Nested query parameters (qs-style)
If the API expects bracketed or indexed keys (a common pain point), qs_codec handles it:
Encoding edge cases (spaces,
%, etc.)qs_codec lets you pick encoding style and avoids double-encoding:
%20+This approach works today without changes to httpx: you bypass the internal params merge (the source of surprises here) and send an already-correct query string.
fix: fix the [issue 3621 of httpx](encode/httpx#3621)
Fix URL parameter merging when both URL and params are provided
Merge params with existing URL query parameters instead of replacing …
Merge params with existing URL query parameters instead of replacing …