Files
box-secondary-development-3/快速接收设备告警/http-server-demo/http-server-token/headers_demo2.py

36 lines
1.0 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import requests
from api.http import Headers as BaseHeaders
from logger import LOGGER
class Headers(BaseHeaders):
def __init__(self):
"""
初始化Headers类
- `self.get_headers_url`: 获取token的URL地址根据实际环境修改。
- `self.timeout`: 请求超时时间设置为5秒。
- `interval`: 定时刷新headers的时间间隔设置为10分钟60秒 * 10
"""
self.get_headers_url = None
self.timeout = 5
interval = 60 * 10
super().__init__(interval)
def _generate_headers(self):
"""
生成请求头的方法_generate_headers方法名不允许修改
固定http请求头authorization以及值可自定义
:return: 请求头字典
"""
try:
headers = {
'authorization': 'Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkXXX'
}
return headers
except:
LOGGER.exception('_generate_headers')
return None