将POST请求从postman导出到Python

2024-06-25 23:15:58 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试用python运行POST请求。当我在Postman中测试时,它运行良好并导入文件。当我在Python中运行它时,我会出错。这将我的计算机上存储的电子表格发布到Quip中。我得到的错误是缺少参数“file”。我试过移动一些东西,但不确定我错过了什么。以下是我的工作内容:

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'))

Tags: 文件importurlresponse计算机filespostmanpost