Skip to content

params overrides query string in url #652

Closed

Description

@j178

Hi,

I noticed a difference between httpx and requests when processing query parameters. I provided the params for the url with query string, requests would merge params into query string, but httpx replaces the whole query string.

Here is a simple script:

import requests
import httpx
import asyncio

URL = 'https://httpbin.org/get?a=1'

r = requests.get(URL, params={'b': 2})
print('requests', r.json()['args'])

async def f():
    r = await httpx.get(URL, params={'b': 2})
    print('httpx', r.json()['args'])
asyncio.run(f())

Results:

requests {'a': '1', 'b': '2'}
httpx {'b': '2'}

Is this an intended behavior?

Activity

  1. lovelydinosaur commented on Dec 20, 2019

    @lovelydinosaur
    Member

    Not intentional, nope.

    It looks like we need to make sure the merge_queryparams also accepts the url, and includes any query params that are included there.

    https://github.com/encode/httpx/blob/master/httpx/client.py#L370-L381

  2. lovelydinosaur commented on Dec 20, 2019

    @lovelydinosaur
    Member

    On second thoughts, we should actually be handling that bit on the URL class itself.

    (So that manually building a request with request = Request(url, params=params) has the right merge behavior too.)

    The signature there is URL(url, params=None). When params are provided they remove any querystring on the url, and replace it with params. Instead we should merge any params argument with any query params that are present in the URL string.

  3. added a commit that references this issue on Aug 1, 2025
    5ba77da
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions