httpx
httpx copied to clipboard
Multipart doesn't support tuple data value
This works:
client.post(
url,
data={"foo": ("1", "2")}, # tuple
)
This works:
client.post(
url,
data={"foo": ["1", "2"]}, # list
files={"test": b"test"},
)
This fails:
client.post(
url,
data={"foo": ("1", "2")}, # tuple
files={"test": b"test"},
)
Traceback
File "httpx/_client.py", line 356, in build_request
return Request(
File "httpx/_models.py", line 336, in __init__
headers, stream = encode_request(content, data, files, json)
File "httpx/_content.py", line 210, in encode_request
return encode_multipart_data(data or {}, files, boundary)
File "httpx/_content.py", line 155, in encode_multipart_data
multipart = MultipartStream(data=data, files=files, boundary=boundary)
File "httpx/_multipart.py", line 188, in __init__
self.fields = list(self._iter_fields(data, files))
File "httpx/_multipart.py", line 198, in _iter_fields
yield DataField(name=name, value=value)
File "httpx/_multipart.py", line 36, in __init__
raise TypeError(
TypeError: Invalid type for value. Expected primitive type, got <class 'tuple'>: ('1', '2')
I guess this line:
https://github.com/encode/httpx/blob/93de1980fa77f15c6b23cbaf2422c0a812caf243/httpx/_multipart.py#L194
should be implemented in the same way as this line:
https://github.com/encode/httpx/blob/93de1980fa77f15c6b23cbaf2422c0a812caf243/httpx/_content.py#L141