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

Missing boundary in content-type leads to Attribute Error #303

Open
ghost opened this issue Feb 2, 2021 · 0 comments
Open

Missing boundary in content-type leads to Attribute Error #303

ghost opened this issue Feb 2, 2021 · 0 comments

Comments

@ghost
Copy link

ghost commented Feb 2, 2021

Hi everybody,

we have a webservice which recently showed a 500 error. The root cause was a malformed multipart request.

Simplified example:

from requests_toolbelt.multipart.decoder import MultipartDecoder

body = b'--boundary xxx'
content_type = 'multipart/form-data'

for part in MultipartDecoder(body, content_type).parts:
	print(part)

Error:
Traceback (most recent call last): File "repr.py", line 6, in <module> for part in MultipartDecoder(body, content_type).parts: File "/venv/lib/python3.7/site-packages/requests_toolbelt/multipart/decoder.py", line 111, in __init__ self._parse_body(content) File "/venv/lib/python3.7/site-packages/requests_toolbelt/multipart/decoder.py", line 137, in _parse_body boundary = b''.join((b'--', self.boundary)) AttributeError: 'MultipartDecoder' object has no attribute 'boundary'

As you see the boundary is missing in the content type. Would it be possible to detect this and raising a better error than AttributeError since AttributeError is very general and hard to catch.
Thanks a lot.

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

0 participants