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")