Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stricter type checking on request data. #3127

Open
1 task done
tomchristie opened this issue Mar 1, 2024 · 1 comment · May be fixed by #3128
Open
1 task done

Stricter type checking on request data. #3127

tomchristie opened this issue Mar 1, 2024 · 1 comment · May be fixed by #3128
Labels
user-experience Ensuring that users have a good experience using the library

Comments

@tomchristie
Copy link
Member

Here's a gnarly thing...

data = {"key": {"this": "ain't json, buddy"}}
httpx.post("https://www.example.com", data=data)

Current behavior is that we'll coerce the value to a string, because we're overly lenient on the types...

>>> r = httpx.post("https://www.example.com", data=data)
>>> r.request.content
b'key=%7B%27this%27%3A+%22ain%27t+json%2C+buddy%22%7D'

Ideally we ought to raise a type error instead...

TypeError: Request data values must be str, int, float, bool, or None. Got type 'dict' for key 'key'.

(For comparison requests also leniently allows this, and also ends up sending unexpected data.)

@tomchristie tomchristie added user-experience Ensuring that users have a good experience using the library fund labels Mar 1, 2024
@tomchristie tomchristie linked a pull request Mar 1, 2024 that will close this issue
@tomchristie tomchristie removed the fund label Mar 1, 2024
@tomchristie
Copy link
Member Author

tomchristie commented Mar 1, 2024

👆🏼 Hmmm... still experimenting with polar here. fund.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
user-experience Ensuring that users have a good experience using the library
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant