Skip to content

Allow params={'pretty':None} to send query arg withOUT an equal sign #1564

Closed

Description

@jamshid

I guess this is a followup to #1261. Please reconsider this:

https://www.python-httpx.org/compatibility/

Query Parameters
requests omits params whose values are None (e.g. requests.get(..., params={"foo": None})). This is not supported by HTTPX.

IMO it would be good and fine to break requests compatibility here.
I doubt many put a no-op "foo":None entry into params when using requests and it's likely nobody has on httpx 0.x.

Query args without an equal sign are in wide usage. E.g. elasticsearch's apis with ?pretty to format the json response or AWS' apis:
https://docs.aws.amazon.com/AmazonS3/latest/userguide/RESTAuthentication.html#ConstructingTheCanonicalizedResourceElement

If the request addresses a subresource, such as ?versioning, ?location, ?acl, ?torrent, ?lifecycle, or ?versionid, append the subresource, its value if it has one, and the question mark.

It's true most apis treat ?foo like ?foo= or ?foo=true but there are apis that treat ?foo= like ?foo=false.
Yes clients probably should give query args explicit values but sometimes you want to use or test an api with a specific url, and httpx should let you construct any legal url.

This is the current requests-compatible but imo undesirable behavior:

$ python3
>>> import json
>>> import httpx
>>> payload = {'key1': 'value1', 'key2': None, 'key3':''}
>>> r = httpx.get('https://httpbin.org/get', params=payload)
>>> print(json.dumps(r.json(), indent=4))
{
    "args": {
        "key1": "value1",
        "key2": "",
        "key3": ""
    },
...
    "url": "https://httpbin.org/get?key1=value1&key2=&key3="
}

Desired behavior:

...
    "url": "https://httpbin.org/get?key1=value1&key2&key3="
}

Activity

  1. changed the title [-]Allow params={'pretty':None} to send query arg with equal sign[/-] [+]Allow params={'pretty':None} to send query arg withOUT an equal sign[/+] on Apr 10, 2021
  2. locked and limited conversation to collaborators on Apr 12, 2021
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