读取文件流,然后通过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'))