Qilan2 commited on
Commit
dbff81f
·
verified ·
1 Parent(s): 1aed9a3

Update server.py

Browse files
Files changed (1) hide show
  1. server.py +14 -7
server.py CHANGED
@@ -124,19 +124,26 @@ def check_api1():
124
  try:
125
  url = "http://127.0.0.1:8000/v1"
126
  response = requests.get(url, timeout=30)
 
 
 
127
  try:
128
  response_json = response.json()
129
- if response_json.get("detail") in ("Forbidden", "Forbidden"):
 
130
  print("SillyTavern已经启动")
131
  break # 接口正常,退出循环
132
  else:
133
- print("SillyTavern未启动" )
134
- except json.JSONDecodeError:
135
- # 如果响应内容不是有效的 JSON,打印错误信息
136
- print("SillyTavern未启动2")
 
 
137
  except requests.exceptions.RequestException as e:
138
- print("SillyTavern未启动3")
139
- time.sleep(5)
 
140
 
141
  # print('开始检测接口状态')
142
  # while True:
 
124
  try:
125
  url = "http://127.0.0.1:8000/v1"
126
  response = requests.get(url, timeout=30)
127
+ response.raise_for_status() # 检查请求是否成功
128
+
129
+ # 尝试解析为 JSON
130
  try:
131
  response_json = response.json()
132
+ # 模糊查找 "Forbidden"
133
+ if "detail" in response_json and "Forbidden" in response_json["detail"]:
134
  print("SillyTavern已经启动")
135
  break # 接口正常,退出循环
136
  else:
137
+ print("SillyTavern未启动")
138
+
139
+ except ValueError: # 捕获 JSON 解码错误
140
+ print("返回的不是有效的 JSON 响应")
141
+ print("原始响应内容:", response.text) # 打印原始文本内容
142
+
143
  except requests.exceptions.RequestException as e:
144
+ print(f"SillyTavern未启动3: {e}") # 打印具体错误信息
145
+
146
+ time.sleep(5) # 等待5秒后重试
147
 
148
  # print('开始检测接口状态')
149
  # while True: