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

Clarification Needed on How to Send JSON Data in Multipart Requests with curl_cffi #404

Closed
TheRealStingo opened this issue Oct 5, 2024 · 2 comments
Labels
question Ask for help or clarification

Comments

@TheRealStingo
Copy link

TheRealStingo commented Oct 5, 2024

Description:
I am currently working with the curl_cffi library and need to send JSON data as part of a multipart request. Specifically, I am looking for guidance on how to correctly send JSON data in a multipart form without using files.

Here is an example of the multipart form data I need to send:

------WebKitFormBoundarywF2oYBwsfEq6mIWK
Content-Disposition: form-data; name="bookerChoicesJson"

{"insurance":{}}
------WebKitFormBoundarywF2oYBwsfEq6mIWK--

However, I have not been able to find clear documentation or examples on how to achieve this using the curl_cffi library. My goal is to send the JSON data ({"insurance":{}}) in the field bookerChoicesJson as a part of the multipart form.

Questions:
How can I send JSON data like the example above using curl_cffi in a multipart request?
Is there a way to manually specify boundaries or should I rely on curl_cffi to generate boundaries automatically?
Are there any best practices for handling multipart requests with JSON data in this library?

@TheRealStingo TheRealStingo added the bug Something isn't working label Oct 5, 2024
@lexiforest
Copy link
Owner

I think you should send them just like normal json files……

from curl_cffi import CurlMime, requests

mp = CurlMime()

mp = CurlMime.from_list(
    [
        {
            "name": "bookerChoicesJson",
            "content_type": "application/json",
            "filename": "whatever.json",
            "data": '{"insurance":{}}',
        },
    ]
)

r = requests.post("https://httpbin.org/post", multipart=mp)

Does this work for you?

@lexiforest lexiforest added question Ask for help or clarification and removed bug Something isn't working labels Oct 6, 2024
@el9in
Copy link

el9in commented Nov 17, 2024

Not working.

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

No branches or pull requests

3 participants