Skip to content

encode_content prevents requests with content=encode_multipart_data(...) from sending by AsyncClient #2399

Answered by tomchristie
wesley800 asked this question in General
Discussion options

You must be logged in to vote

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)

The other is to build a new interface SyncAndAsyncIteratorByteStream and change enc…

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@wesley800
Comment options

@tomchristie
Comment options

@wesley800
Comment options

Answer selected by wesley800
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #2377 on October 06, 2022 11:30.