requests icon indicating copy to clipboard operation
requests copied to clipboard

POST Multipart-Encoding does not work if the Content-Type header has been previously defined in the session

Open stephane-klein opened this issue 5 months ago • 2 comments

Hi,

I just wasted two hours because it seems that the POST Multiple Multipart-Encoded Files function does not work if a Content-Type has been previously defined at the session level.

Example:


...

session.headers.update({“Content-Type”: “application/json”})

...

response = session.post(
    “http://localhost:3000/api/v1/pipelines/upload”,
    files={
        “file”: (“hello_world3.py”, f, “text/x-python”)
    },
    data={
        “urlIdx”: “2”
    }
)

Two suggestions:

  • a. Either modify the implementation of POST Multiple Multipart-Encoded Files to overwrite the content of the Content-Type header even if it has been defined at the session level
  • b. Or issue a warning message to inform the developer of their possible error

What do you think?

Best regards, Stéphane

stephane-klein avatar Jul 17 '25 14:07 stephane-klein

Folks ignore warnings or complain about them because "They meant to do that". We used to have docs that warned against what you're doing explicitly as well as setting things like the "Host" header. I don't know when those documentation warnings were removed (or if sphinx just isn't finding them in the search) but that's the best you're going to get.

This behaviour has been the standard for the library since 0.x and is one of the few things that didn't break in 1.x or 2.x.

sigmavirus24 avatar Jul 18 '25 23:07 sigmavirus24

Hi maintainers,

I'd like to work on this issue and propose a solution. Could you please assign this task to me?

Thank you!

pras529 avatar Jul 19 '25 13:07 pras529