https://www.jb51.net/article/105050.htm
from requests import request import unittest from Common.HandleConfig import conf import urllib3 import os urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning) class DownLoadCategoryAttributeTemplate(unittest.TestCase): """类目属性模板-下载""" def test_downLoadCategoryAttributeTemplate(self): url = conf.get("product_url", "test") + "/productManage/categoryAttribute/exportCategoryAttributeTemplate" print(url) headers = {"Content-Type": "application/json", "authtype": "oidc", "authorization": conf.get("product_url", "authorization")} response = request(method="get", url=url, headers=headers, verify=False) print(response) print(response.status_code) # 返回值为字节流,所以要加b,w表示文件以可写模式打开 with open("下载模板.xlsx", "wb") as f: f.write(response.content) # 校验文件是否存在 assert os.path.exists("下载模板.xlsx")