文件上传接口
api: POST http://host/api/import
接口入参:file:文件内容
import os
import urllib3
import ast
def import_by_rest(self, file_path):
"""
:param :file_path:导入文件路径
:return :res:接口返回数据
"""
api = "http://host/api/import"
file_name = os.path.basename(file_path)
fields = {"file": (file_name, open(file_path, "rb").read())}
headers = {"charset": "utf-8"}
headers["Content-Type"] = "multipart/form-data; boundary=------WebKitFormBoundaryFJ1qMeiyjBLQBNas"
response = urllib3.PoolManager().request("post", api, fields=fields, headers=headers, multipart_boundary="------WebKitFormBoundaryFJ1qMeiyjBLQBNas")
res = ast.literal_eval(response.data.decode('utf-8'))
assert response.status is 200, res
return res