Comments (13)
Okay. Multipart encoded data can only handle string or File data. We could perfectly well either coerce a limited set of scalar types, or just coerce any inputs with str()
from httpx.
Would probably be a useful point of reference to stay in line with whatever urllib3 currently does.
from httpx.
https://github.com/urllib3/urllib3/blob/master/src/urllib3/filepost.py#L84-L90
urllib3 isn't doing anything particularly advanced either. i can make a PR with a similar solution if you are fine with it.
from httpx.
So looks like urllib3 only accepts str/byte values. What does requests do for that case? If it coerces to str, then any idea where it does that?
from httpx.
Most of the fiddly magic in requests happens in requests.models:_encode_files. Quite a bit of knowledge implemented which can help us. Prepared data is then sent to urllib.filepost:encode_multipart_formdata we've already checked above.
Another edge case i came across reading this code are None
values in data
which would have to be handled in http3.multipart:multipart_encode
from httpx.
Okay, so to keep in the with the behaviour I can see there, we should:
- Ignore
None
values. - Cast any non-str/bytes to str.
- Handle lists of args.
from httpx.
I already posted in the PR (didn't realize this was the issue for that PR until looking further down the list) but I'm not a fan of blindly casting objects that are passed in to strings and then shipping that. Why not raise an error in that situation?
from httpx.
my argument would be that data ends up as string in multipart form body anyway and interface should let user go as far as reasonably possible before raising errors.
from httpx.
There's no right answer here - either API could be an resonable design choice.
I think we should probably prefer to nail things down quite tightly - given that we've got properly typed interfaces all the way through, it'd be nice if we worked towards raising TypeError
on any incorrect type passed to one of our public interfaces.
from httpx.
We should strive towards no typing.Any
usage in public interfaces. :)
from httpx.
Does this imply this issue is a non-issue then? It already works as expected under current implementation. Should libraries using http3
convert passed values in data
dict according to interface?
from httpx.
I guess there's still some issues to be resolved here:
- Ensure we deal with list of str / list of bytes okay.
- Ensure we raise
TypeError
on any dict values other thanbytes|str|typing.List[bytes]|typing.List[str]
. - Ensure we raise
TypeError
on any dict keys other thanstr
.
Slightly depends on exactly which points we intend to perform the type checking at.
from httpx.
Can this issue be closed now?
from httpx.
Related Issues (20)
- add more type checking in params/form-data HOT 12
- Requests for new public APIs HOT 9
- Install httpx without pulling anyio, trio and socks HOT 1
- Pressure test httpx Slower and slower HOT 4
- 502 Error When Using Global Proxy
- Shipping broken. "Could not find module httpx" even when installed.
- Authentification docs reference non-existing class HOT 2
- `httpx.AsyncClient` has much worse performance than `aiohttp.ClientSession` with concurrent requests HOT 22
- HTTPX and Celery \ GEvent Issue HOT 3
- Not support "no_proxy" including value of ipv6 prefix style
- http2协议发送请求会发送两次,第一次数据,第二次空包End Stream,如何将第二次空包的End Stream放到第一次包中
- Support IDNA2003 HOT 2
- How to implement failed retry
- BasicAuth vs BasicAuthentication HOT 2
- Httpx connection Nonetype error
- Change default encoding to utf-8 in `normalize_header_key` and `normalize_header_value` functions HOT 4
- httpx能支持get或者post请求的时候传入代理,而不是httpx.AsyncClient初始化的时候传入吗
- Random httpx.ConnectError
- How to force enable HTTP/2.0 HOT 5
- Module 'httpx' has no attribute 'BasicAuthentication' - Documentation is not up-to-date
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from httpx.