[Python] Python request - the request was rejected because no multipart boundary was found

Discussão em 'Python' iniciado por Stack, Junho 29, 2025.

  1. Stack

    Stack Membro Participativo

    (I'm still new to API endpoints in python so apologies if I am missing an easy answer here, but I haven't been able to find it.)

    I'm trying to make a post request to an endpoint that uses a multipart/form-data request, where you include a file to be uploaded.

    I'm attempting to post the following:

    import requests

    url = &&&
    headers = {'Content-Type': 'multipart/form-data',
    'Authorization': authtoken,
    'x-api-key': x_api_key,
    'Accept': 'application/vnd.###.v1+json'}
    files = {'file': ('filename.csv', open('filename.csv', 'rb'),'text/csv')}
    r = requests.post(url, headers=headers, files=files, verify=False)
    r.text


    (Note that "&&&" and "###" represent confidential links.)

    I get this error:

    "status":500,"error":"Internal Server Error","message":"Failed to parse multipart servlet request; nested exception is java.io.IOException: org.apache.tomcat.util.http.fileupload.FileUploadException: the request was rejected because no multipart boundary was found","path":"&&&"

    I'm not sure what I'm missing here. Do I need to set a multipart boundary? How can I do so? If it seems like you need more info to answer this question, please let me know.

    Thank you!

    Continue reading...

Compartilhe esta Página