|
import requests |
|
import os |
|
|
|
|
|
|
|
def app_register_user(data, url="http://localhost:8000/users/regByCamera"): |
|
|
|
api_key = os.environ["Mama_API_Key"] |
|
response = requests.post(url, |
|
json=data, |
|
headers={"Content-Type": "application/json", |
|
"mama_api_key": api_key}) |
|
|
|
|
|
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"): |
|
|
|
api_key = os.environ["Mama_API_Key"] |
|
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__": |
|
|
|
|
|
print(app_get_user()) |
|
|