first commit

This commit is contained in:
weiweiw 2024-06-21 13:28:47 +08:00
parent c5edea9522
commit 607fa53553
2 changed files with 8 additions and 1 deletions

BIN
.DS_Store vendored

Binary file not shown.

View File

@ -137,10 +137,13 @@ class ApiRequest:
try:
if chunk.startswith("data: "):
data = json.loads(chunk[6:-2])
pprint(data,depth=1)
elif chunk.startswith(":"): # skip sse comment line
continue
else:
data = json.loads(chunk)
pprint(data,depth=1)
#print(f"{data}")
yield data
except Exception as e:
msg = f"接口返回json错误 {chunk}’。错误信息是:{e}"
@ -173,17 +176,21 @@ class ApiRequest:
try:
if chunk.startswith("data: "):
data = json.loads(chunk[6:-2])
print("ret_sync, data = json.loads(chunk[6:-2])")
pprint(data,depth=1)
elif chunk.startswith(":"): # skip sse comment line
continue
else:
# print(f"{chunk}")
data = json.loads(chunk)
print("ret_sync, data = json.loads(chunk)")
pprint(data,depth=1)
yield data
except Exception as e:
msg = f"接口返回json错误 {chunk}’。错误信息是:{e}"
logger.error(f'{e.__class__.__name__}: {msg}',
exc_info=e if log_verbose else None)
else:
# print(chunk, end="", flush=True)
yield chunk
except httpx.ConnectError as e:
msg = f"无法连接API服务器请确认 api.py 已正常启动。({e})"