encode_content prevents requests with content=encode_multipart_data(...) from sending by AsyncClient #2399
-
This problem is basically an extension of #2341 . Suppose one wants to send a POST request with multipart-encoded form data (but NOT uploading files), without any cookie sessions. One way to do that is to build something like: ac = httpx.AsyncClient()
formdata = {"user":"John","pwd":"secret!"}
header, content = httpx._content.encode_multipart_data(formdata, {}, b'----WebkitRandomBoundary')
req = httpx.Request("POST", 'https://example.org/login', content=content, headers=header)
res = await ac.send(req, auth=None, follow_redirects=False)
Although I guess there's two solutions. One is to add a |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
I'm going to push this into a discussion, since you're using a private API... httpx._content.encode_multipart_data
# ^ The underscore indicates that you're accessing a private attribute.
# Our public API is always available directly as `httpx.<...>` I'd tweak what you're doing like this... header, stream = httpx._content.encode_multipart_data(formdata, {}, b'----WebkitRandomBoundary')
content = b''.join[(part for part in stream)] # You're not actually using async IO here, so just grab the content as bytes.
req = httpx.Request("POST", 'https://example.org/login', content=content, headers=header)
True. There's possibly? an issue here at the public API level, if we decided that "content = ..." should support instances that are both iterators and async iterators. Not sure really. |
Beta Was this translation helpful? Give feedback.
I'm going to push this into a discussion, since you're using a private API...
I'd tweak what you're doing like this...