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