twisted / treq

Python requests like API built on top of Twisted's HTTP client.
Other
587 stars 140 forks source link

Improve error message for short/long file tuples #299

Closed twm closed 3 years ago

twm commented 4 years ago

If passed a tuple with a length other than 2 or 3 IBodyProducer would end up trying to adapt None, producing this confusing message:

Traceback (most recent call last):
  File ".../treq/test/test_client.py", line 513, in test_request_files_bad_tuples
    self.client.request(
  File ".../treq/client.py", line 190, in request
    bodyProducer, contentType = self._request_body(
  File ".../treq/client.py", line 297, in _request_body
    files = list(_convert_files(files, stacklevel=stacklevel + 2))
  File ".../treq/client.py", line 388, in _convert_files
    yield (param, (file_name, content_type, IBodyProducer(fobj)))
builtins.TypeError: ('Could not adapt', None, <InterfaceClass twisted.web.iweb.IBodyProducer>)

This changeset produces a TypeError that mentions tuple length.

twm commented 3 years ago

Thank you for the review @adiroiban!