This commit is contained in:
恍兮惚兮 2024-08-29 21:33:22 +08:00
parent 262021406e
commit e789be80cc
2 changed files with 3 additions and 1 deletions

View File

@ -82,6 +82,7 @@ class gptcommon(basetrans):
message = "" message = ""
if not response.headers["Content-Type"].startswith("text/event-stream"): if not response.headers["Content-Type"].startswith("text/event-stream"):
# application/json # application/json
# text/html
raise Exception(response.text) raise Exception(response.text)
for chunk in response.iter_lines(): for chunk in response.iter_lines():
response_data = chunk.decode("utf-8").strip() response_data = chunk.decode("utf-8").strip()

View File

@ -189,7 +189,8 @@ class TS(basetrans):
) )
except requests.RequestException: except requests.RequestException:
raise ValueError(f"连接到Sakura API超时{self.api_url}") raise ValueError(f"连接到Sakura API超时{self.api_url}")
if not output.headers["Content-Type"].startswith("text/event-stream"):
raise Exception(output.text)
for o in output.iter_lines(): for o in output.iter_lines():
try: try:
res = o.decode("utf-8").strip()[6:] # .replace("data: ", "") res = o.decode("utf-8").strip()[6:] # .replace("data: ", "")