接口自动化测试---文件上传

import requests


HOST="http://127.0.0.1:80"
fileUpload_path = "/user/doUpload"
fileUpload_data = {
    "file": ("窗口.png", open("../../static/images/窗口.png", "rb"), "image/png")
}


class FileUpload:
    def __init__(self, path, indata):
        self.url = f'{HOST}{path}'
        self.headers = {
            "Content-Type": "multipart/form-data",
        }
        self.payload = indata
        self.response = requests.post(self.url, files=self.payload)

    def get_response_json(self):
        return self.response.json()


fileUpload = FileUpload(fileUpload_path, fileUpload_data)
print(fileUpload.get_response_json())

 

需要关注的:

payload={

请求体格式(files):(文件名,文件句柄,文件格式类型)

}

requests.post(files=payload)

 

 

你可能感兴趣的:(接口自动化测试)