import requests import os # 注册/更新进数据库 def app_register_user(data, url="http://localhost:8000/users/regByCamera"): # 发起POST请求 api_key = os.environ["Mama_API_Key"] # 获取token response = requests.post(url, json=data, headers={"Content-Type": "application/json", "mama_api_key": api_key}) # 获取JSON响应 if response.status_code == 200: # 检查响应是否为空 if response.text.strip(): try: json_response = response.json() print(json_response) except ValueError as e: print(f"解析JSON响应失败: {e}") return [] else: print("回应为空") return [] else: print(f"回应失败状态码:{response.status_code}") return [] # 从数据库获取被动用户数据 def app_get_user(url="http://localhost:8000/users/getUserInfo"): # 发起GET请求 api_key = os.environ["Mama_API_Key"] # 获取token response = requests.get(url, headers={"Content-Type": "application/json", "mama_api_key": api_key}) # 获取响应内容 if response.status_code == 200: # 检查响应是否为空 if response.text.strip(): try: data_list = response.json() return data_list except ValueError as e: print(f"解析JSON响应失败: {e}") return [] else: print("回应为空") return [] else: print(f"回应失败状态码:{response.status_code}") return [] if __name__ == "__main__": # app_register_user() # 注册/更新数据库 # app_get_user() # 从数据库获取被动用户数据 print(app_get_user())