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

Sending a zero-part multipart document has an uncaught exception; .parts should be an empty list instead #345

Open
dragon-dxw opened this issue Dec 14, 2022 · 1 comment

Comments

@dragon-dxw
Copy link

If returning a list-like object, MarkLogic can return a multipart document, one part per returned value.
For an empty list, it returns zero parts (i.e. no bytes). Requests Toolbelt crashes in this instance, because the assumption that a content type must exist at all is violated.

File /usr/local/lib/python3.9/site-packages/caselawclient/Client.py:29 in decode_multipart
multipart_data = decoder.MultipartDecoder.from_response(response)
File /usr/local/lib/python3.9/site-packages/requests_toolbelt/multipart/decoder.py:156 in from_response
return cls(content, content_type, encoding)
File /usr/local/lib/python3.9/site-packages/requests_toolbelt/multipart/decoder.py:110 in __init__
self._find_boundary()
File /usr/local/lib/python3.9/site-packages/requests_toolbelt/multipart/decoder.py:114 in _find_boundary
ct_info = tuple(x.strip() for x in self.content_type.split(';'))
AttributeError: 'NoneType' object has no attribute 'split'

We got around this by hardcoding that no content means zero items returned, but this feels like a thing worth solving at the library level.
our workaround: https://github.com/nationalarchives/ds-caselaw-custom-api-client/pull/99/files

@sigmavirus24
Copy link
Collaborator

Want to send a PR? I think it should be relatively simple to add this logic/handling

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

No branches or pull requests

2 participants