Need help uploading a file via API with Python (multipart request)?

I’m very confused on how to format my file as a multipart request stored in a variable. The current code is invalid syntax, I can get it to post when formatted as one string but the data doesn’t deliver so I get an error response. How do I format it properly? Here is my code:

import requests

with open('monday_key.txt') as f:
    apiKey = f.read()
apiUrl = "https://api.monday.com/v2/file"
headers = {"Authorization": apiKey}
file = {'file': open('safety_reviews/jjjj.pdf', 'rb' )}
data =  {'mutation' { 'add_file_to_column' ['item_id': '3366726997', 'column_id': "files", '$file': file ] { 'id' }}}
r = requests.post(url=apiUrl, json=data, headers=headers)

print (r.content)

Hello @levi!

You can check out this example we made for Postman and then from Postman, export it to the language you want to use.

I hope that helps!

Cheers,
Matias