requests post接口模拟上传文件

读取文件流,然后通过post请求种files参数进行发送模拟

import os
import requests

current_file = os.path.dirname(__file__)
data_file = os.path.join(current_file,'data/demo.xlsx')

excel_file = {'file': ('demo.xlsx', open(data_file, 'rb'), 'application/vnd.ms-excel', {'Expires': '0'})}
#post接口上传文件加参数files
response = requests.post(url= 'http://httpbin.org/post',files= data_file)
print(response.content.decode('utf-8'))
posted @ 2022-04-12 16:37  我是海底的咸鱼  阅读(216)  评论(0编辑  收藏  举报