python實現文件下載


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

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM