第二天,封装headers

# -*- encoding: utf-8 -*-

from http_request import RequestHttp

URL = "127.0.0.1/api/"

class Headers:
    
    def __init__(self):
        self.host = URL
        self.base_url = "http://" + self.host
    
    #请求登录,获取授权返回
    def get_login_authorization(self):
        request = RequestHttp()
        response = request.request_http(
            method='POST',
            url=self.base_url + "login",
            json={
                "username": "admin",
                "password": "123456",
                "uuid": "360bf1a4cf9e46f387521fca331a6c4f"
            },
            headers=None
        ).json()
        Authorization = "Bearer " + response["data"]
        return Authorization
    
    def create_headers(self):
        Authorization = self.get_login_authorization()
        headers = {"Authorization": Authorization,
                   "content-type": "application/json"}
        headers["Accept"] = "application/json, text/plain, */*"
        return headers

if __name__ == "__main__":
    hd = Headers()
    headers = hd.create_headers()
    print(headers)
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值