You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

46 lines
1.1 KiB
Python

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

import requests
import json
import requests
import base64
from log import logger
with open('cfg.json', 'r') as f:
cfg_dict = json.load(f)
def encode_info(info):
"""
加密
"""
encoded_info = base64.b64encode(info.encode('utf-8')).decode("utf-8")
return encoded_info
def decode_info(encoded_info):
"""
解密
"""
info = base64.b64decode(encoded_info.encode('utf-8')).decode('utf-8')
return info
class SendResult:
def __init__(self, url):
self.url = url
self.username = decode_info(cfg_dict['username'])
self.password = decode_info(cfg_dict['password'])
self.headers = {'Content-type': 'video/mp4', 'Authorization': 'Basic ' + f'<{self.username}>:<{self.password}>'}
def post(self, file_path):
try:
response = requests.post(self.url, files=file_path, headers=self.headers)
except Exception as e:
logger.error(f'post请求错误{e}')
return None
return response
if __name__ == '__main__':
send_result_obj = SendResult()
send_result_obj.post('test.mp4v')