Skip to content

Httpx behaving differently than requests? #3117

@EricPanDev

Description

@EricPanDev

the data paramater in httpx.post and httpx.client.post behave differently than requests.post

Example with discord's API:

This will not work

import httpx

header = {
    'Authorization': "Bot token",
}

files = {
    "file": ("hi.png", open("./image.png", 'rb'), "image/png")
}

payload = {
    "content": "pls work",
    "allowed_mentions": {
        "parse": []
    }
}

channel_id = "1079501847720640682"

r = httpx.post(f"https://discord.com/api/v9/channels/{channel_id}/messages", data=payload, headers=header, files=files)

print(r.status_code)
print(r.text)

However with requests, this will work fine

import requests

header = {
    'Authorization': "Bot token",
}

files = {
    "file": ("hi.png", open("./image.png", 'rb'), "image/png")
}

payload = {
    "content": "pls work",
    "allowed_mentions": {
        "parse": []
    }
}

channel_id = "1079501847720640682"

r = requests.post(f"https://discord.com/api/v9/channels/{channel_id}/messages", data=payload, headers=header, files=files)

print(r.status_code)
print(r.text)

I am unsure if this is a bug or if I need to pass these arguments differently in httpx

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions