You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Raising incorrect error when passing array to data #3471
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.
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.
@AS7RIDENIED : I don't think you can pass in anything other than a dictionary with lists as values for form data. I tried this and it returned a 200:
@AS7RIDENIED : I don't think you can pass in anything other than a dictionary with lists as values for form data. I tried this and it returned a 200:
The essence of this issue is that the httpx returns an incorrect error when working with an asynchronous client. I know what can be passed and what cannot, thanks
TypeError: sequence item 1: expected a bytes-like object, dict found
happens because data=[{"a": "b"}] gets passed all the way to h11 when using Client.
With AsyncClient, the same input fails earlier in _send_single_request, but the error message is misleading — it says it's a sync request issue, when the real problem is the invalid data format.
The root cause is that _content.encode_request() doesn't validate data properly. A fix would be to add type checks there to catch invalid formats like lists of dicts early on.
Activity
bagowix commentedon Jan 22, 2025
Hi!
I have not been able to replicate this error, it currently returns “Use ‘content=<...>’ to upload raw bytes/text content.”
AS7RIDENIED commentedon Jan 23, 2025
I just created a venv, installed httpx, and got the same exceptions as mentioned above. Also tried with python 3.12.8 but got same result
There is some data and traceback
jfleach commentedon Mar 13, 2025
@AS7RIDENIED : I don't think you can pass in anything other than a dictionary with lists as values for form data. I tried this and it returned a 200:
with this data:
Reference: https://www.python-httpx.org/compatibility/#query-parameters
AS7RIDENIED commentedon Mar 20, 2025
The essence of this issue is that the httpx returns an incorrect error when working with an asynchronous client. I know what can be passed and what cannot, thanks
sreeharin commentedon May 30, 2025
Hey, I looked into this issue and the error
happens because
data=[{"a": "b"}]gets passed all the way toh11when using Client.With AsyncClient, the same input fails earlier in
_send_single_request, but the error message is misleading — it says it's a sync request issue, when the real problem is the invalid data format.The root cause is that
_content.encode_request()doesn't validatedataproperly. A fix would be to add type checks there to catch invalid formats like lists of dicts early on.tiny-pangolin commentedon Jan 1, 2026
I was able to work around this by using
json=datainstead of data=data`Fix confusing error message for invalid data parameter