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 response preserve carriage return linefeed pairs #6834

Closed
rimmartin opened this issue Nov 27, 2024 · 1 comment
Closed

multipart response preserve carriage return linefeed pairs #6834

rimmartin opened this issue Nov 27, 2024 · 1 comment
Labels
actions/autoclose-qa Used for automation to auto-close an issue Question/Not a bug

Comments

@rimmartin
Copy link

Hi,
Trying to process the response that is a multipart/form-data.

    multipart_data = MultipartDecoder.from_response(response)
    for part in multipart_data.parts:
        print(part.content)
        print(part.headers)

which fails with requests_toolbelt.multipart.decoder.ImproperBodyPartContentException: content does not contain CR-LF-CR-LF
And when I try to get to the body of the response(runtime version 2.32.3) any other way the "\r\n"'s don't exist.
response headers are

HTTPHeaderDict({'Content-Length': '120640', 'Connection': 'Keep-Alive', 'Content-Type': 'multipart/form-data; boundary=e9bb939421e7436ebdbec45d4142245e'})
status=200

Started with conda env yesterday

conda create -n pytest_env python
conda activate pytest_env
conda install -c conda-forge requests-toolbelt pytest requests -y
        response = requests.post(
            endpoint,
            data=mpb,
            headers=headers,
            verify=False,  # Disable SSL verification for HTTPS
            timeout=50,  # Set timeout to 50 seconds
            stream=True
        )

is the POST request and it sends over a multpart via toolbelt's MultipartEncoder.

After response returns tried sending content to binary file out and see no "\r\n"'s there either.

    with open("debug.txt", "wb") as debug_file:
        for chunk in response:
            debug_file.write(chunk)

I've written nodejs & Java clients that leave the response "\r\n"'s alone and I have choices of how the response body gets processed.

Is there a setting for requests that corrects this behavior? Many suggestions out on the wild web but none successful so far

@rimmartin rimmartin added actions/autoclose-qa Used for automation to auto-close an issue Question/Not a bug labels Nov 27, 2024
Copy link

As described in the template, we won't be able to answer questions on this issue tracker. Please use Stack Overflow

@github-actions github-actions bot locked as off-topic and limited conversation to collaborators Nov 27, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
actions/autoclose-qa Used for automation to auto-close an issue Question/Not a bug
Projects
None yet
Development

No branches or pull requests

1 participant