Skip to content

httpx is deleting url query parameters that do not explicitly specify a value #2331

Closed

Description

@fastily

The following program

import asyncio
import httpx

async def main():
    async with httpx.AsyncClient() as client:
        r = await client.get("https://httpbin.org/get?foobar", params={'hello': "world"})
        print(r.url)

asyncio.run(main())

should print https://httpbin.org/get?hello=world&foobar

However, the actual output is https://httpbin.org/get?hello=world

It appears that httpx is deleting url query parameters that do not explicitly specify a value.

Thanks for having a look

Activity

  1. blablatdinov commented on Aug 5, 2022

    @blablatdinov

    Good afternoon!

    This case reproduce in httpx.Client. If such behaviour is bug, I want to fix it

  2. lovelydinosaur commented on Aug 5, 2022

    @lovelydinosaur
    Member

    It appears that httpx is deleting url query parameters that do not explicitly specify a value.

    To determine if your assessment here is correct, try the same example but with foobar=something.

  3. blablatdinov commented on Aug 5, 2022

    @blablatdinov

    @tomchristie you're right if use key-value pair in url, it's work. But what to do in case of query param without value (only key). In this discussion I found the opinion, that query can contain query param wiithout value

  4. fastily commented on Aug 6, 2022

    @fastily
    Author

    It appears that httpx is deleting url query parameters that do not explicitly specify a value.

    To determine if your assessment here is correct, try the same example but with foobar=something.

    It works fine? That isn't related to the bug I'm reporting however. Have you tried running my example? Url parameters that do not have an explicit value are being deleted.

  5. lovelydinosaur commented on Aug 10, 2022

    @lovelydinosaur
    Member

    To determine if your assessment here is correct, try the same example but with foobar=something.

    It works fine? That isn't related to the bug I'm reporting however.

    Great, so we've determined that your assessment is correct. This is specifically occurring for parameters without a value.

    So, yes, that looks broken to me.

    Confirmed this to myself with...

    import httpx
    
    r = httpx.get("https://httpbin.org/get?foobar", params={'hello': "world"})
    print(r.request.url)  # https://httpbin.org/get?hello=world
    
    r = httpx.get("https://httpbin.org/get?foobar=abc", params={'hello': "world"})
    print(r.request.url)  # https://httpbin.org/get?foobar=abc&hello=world
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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions