yangtb24 commited on
Commit
fc75899
·
verified ·
1 Parent(s): 9901878

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -5
app.py CHANGED
@@ -50,11 +50,11 @@ def get_credit_summary(api_key):
50
  "Authorization": f"Bearer {api_key}",
51
  "Content-Type": "application/json"
52
  }
53
- max_retries = 5
54
- retry_delay = 5
55
  for attempt in range(max_retries):
56
  try:
57
- response = requests.get(API_ENDPOINT, headers=headers, timeout=5)
58
  response.raise_for_status()
59
  data = response.json().get("data", {})
60
  total_balance = data.get("totalBalance", 0)
@@ -63,10 +63,10 @@ def get_credit_summary(api_key):
63
  except requests.exceptions.Timeout as e:
64
  logging.error(f"获取额度信息失败,API Key:{api_key},尝试次数:{attempt+1}/{max_retries},错误信息:{e} (Timeout)")
65
  if attempt < max_retries - 1:
66
- time.sleep(retry_delay)
67
  else:
68
  logging.error(f"获取额度信息失败,API Key:{api_key},所有重试次数均已失败 (Timeout)")
69
- except RequestException as e:
70
  logging.error(f"获取额度信息失败,API Key:{api_key},错误信息:{e}")
71
  return None
72
  return None
 
50
  "Authorization": f"Bearer {api_key}",
51
  "Content-Type": "application/json"
52
  }
53
+ max_retries = 3
54
+
55
  for attempt in range(max_retries):
56
  try:
57
+ response = requests.get(API_ENDPOINT, headers=headers, timeout=3)
58
  response.raise_for_status()
59
  data = response.json().get("data", {})
60
  total_balance = data.get("totalBalance", 0)
 
63
  except requests.exceptions.Timeout as e:
64
  logging.error(f"获取额度信息失败,API Key:{api_key},尝试次数:{attempt+1}/{max_retries},错误信息:{e} (Timeout)")
65
  if attempt < max_retries - 1:
66
+ pass
67
  else:
68
  logging.error(f"获取额度信息失败,API Key:{api_key},所有重试次数均已失败 (Timeout)")
69
+ except requests.exceptions.RequestException as e:
70
  logging.error(f"获取额度信息失败,API Key:{api_key},错误信息:{e}")
71
  return None
72
  return None