Skip to content

Raising incorrect error when passing array to data #3471

Open
@AS7RIDENIED

Description

httpx Version: 0.28.1

import asyncio, httpx

async def test():
    sync_client = httpx.Client(base_url="https://httpbin.org")
    async_client = httpx.AsyncClient(base_url="https://httpbin.org")

    try:
        response = await async_client.request("POST", "/post", data=[{"a": "b"}])
        print(response)
    except Exception as e:
        print(e)

    try:    
        response = sync_client.request("POST", "/post", data=[{"a": "b"}])
        print(response)
    except Exception as e:
        print(e)


asyncio.run(test())
Attempted to send an sync request with an AsyncClient instance.
sequence item 1: expected a bytes-like object, dict found

In data, judging by the code sources, you can only pass strings, dictionaries, or bytes (+= arrays of bytes). If you pass any array other than a byte array to data, it will raise an incorrect error: Attempted to send a sync request with an AsyncClient instance. (We're using an asynchronous client to send an asynchronous request, mhm)
Honestly, I'm too lazy to look through the sources and figure out what went wrong, but in general, it should return the same error as it does with a synchronous client - sequence item 1: expected a bytes-like object, dict found.

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