Export POST Request from postman to Python

4.3k views Asked by At

I am attempting to run a POST request in python. When I test in Postman it runs fine and imports the file. When I run it in Python I error out. This posts a spreadsheet stored on my computer into Quip. I am getting the error missing argument 'file'. I have tried moving several things around and am not sure what im missing. here is what im working with:

import requests

url = "https://platform.quip.com/1/threads/import-file"

payload = {'type': 'spreadsheet'}
files = [
('file', open('/Users/admin/Documents/excel/logs/Output/test.xlsx','rb'))
]
headers = {
'Content-Type': 'application/x-www-form-urlencoded',
'Authorization': 'Bearer **************************='
}

response = requests.request("POST", url, headers=headers, data = payload, files = files)

print(response.text.encode('utf8'))
1

There are 1 answers

0
sekrett On

Try to change this line:

files = {'file': open('/Users/admin/Documents/excel/logs/Output/test.xlsx','rb')}

Also I noticed a bug in Postman (version 9.9.1): payload contains only the first field. Be aware of that.

So I would not rely on generated code.