Multipart/related POST API query with csv file to upload using python

I am trying to automate a POST query with Content-Type multipart/related, and body is “form-data” with a csv file attachment and json metadata.
below is the curl query for the API:

curl --location --request POST '' \ --header 'Authorization: Bearer <token>' \ --header 'Accept: application/json' \ --header 'Content-Type: multipart/related' \ --form 'attachment=@"testing.csv"' \ --form 'metaData="{\"category\": \"test\", \"properties\":{\"input\":[\"xyz\"], \"output\":[\"abc\"]}}"

i have tried like below :

values = {"category": "test", "properties": {"input": "xyz", "output": "abc"}}
files = {'attachment': open('testing.csv','rb')}
head = {"authorization": "Bearer" +TOKEN, "accept": "application/json", "content-type": "multipart/related"}
url = ""

r =, files=files, data=values, headers=head)

print(r.text, r.status_code)

this gives me below output:


but if i change the headers value to only limited to “TOKEN” and dont add any other headers, it goes through and gives error for missing “metaData”, since it requires “metaData” as “form-data” body with the attachment csv file.

head = {"authorization": "Bearer" +TOKEN}

output is below:

[{"code":"0001","fieldName":"metaData","message":"metaData required"}] 200

I have tried with json=values as well, it gives the same error.

Is there a way to get this done using requests? Or is there another tool that I should be looking at? Please help.