Httpx behaving differently than requests? #3118
Replies: 7 comments 2 replies
-
|
Here is the console output |
Beta Was this translation helpful? Give feedback.
-
|
the APIs are slightly different, it looks like |
Beta Was this translation helpful? Give feedback.
-
|
I mean it works fine if the dict passed to the data paramater only has one item in httpx, but if I have 2 or more keys it raises that error |
Beta Was this translation helpful? Give feedback.
-
|
Thanks for the question... Form data (URL encoded or Multipart) can only represent plain data. Everything on the wire is just a string, so we don't want There's scope for:
|
Beta Was this translation helpful? Give feedback.
-
|
Wait so then what would be the equivalent in httpx? Would I pass a url encoded string to data or..? |
Beta Was this translation helpful? Give feedback.
-
|
This discussion is probably about Discord API parameters. I'm interested in the Discord API, so I looked into it ... https://discord.com/developers/docs/reference#uploading-files
This solves the problem. import json
...
payload_json = {"payload_json": json.dumps(payload)}
r = httpx.post(f"https://discord.com/api/v9/channels/{channel_id}/messages", data=payload_json, headers=header, files=files)✅ I don't know if the form data encoding of |
Beta Was this translation helpful? Give feedback.
-
|
I think Httpx shoud be like reqests to automatically decode the byte type in the form to the str type, |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
the data paramater in httpx.post and httpx.client.post behave differently than requests.post
Example with discord's API:
This will not work
However with requests, this will work fine
I am unsure if this is a bug or if I need to pass these arguments differently in httpx
Beta Was this translation helpful? Give feedback.
All reactions