Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multipart doesn't support tuple data value #2322

Closed
andreymal opened this issue Jul 29, 2022 · 1 comment · Fixed by #2355
Closed

Multipart doesn't support tuple data value #2322

andreymal opened this issue Jul 29, 2022 · 1 comment · Fixed by #2355

Comments

@andreymal
Copy link

andreymal commented Jul 29, 2022

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:

if isinstance(value, list):

should be implemented in the same way as this line:

if isinstance(value, (list, tuple)):

@tomchristie
Copy link
Member

Fair enough, yup.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants