Skip to content

Commit b2bc338

Browse files
zhansheng.lzsclaude
andcommitted
fix: correct exception types in transcription modules
BaseAsyncApi uses sync requests.Session() under the hood (the "Async" refers to DashScope server-side task polling, not Python async I/O). Switch from asyncio/aiohttp exceptions to requests.Timeout and requests.ConnectionError to ensure retry logic actually catches real network errors. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
1 parent cfb77f2 commit b2bc338

2 files changed

Lines changed: 6 additions & 8 deletions

File tree

dashscope/audio/asr/transcription.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
# -*- coding: utf-8 -*-
22
# Copyright (c) Alibaba, Inc. and its affiliates.
33

4-
import asyncio
54
import time
65
from typing import List, Union
76

8-
import aiohttp
7+
import requests
98

109
from dashscope.api_entities.dashscope_response import (
1110
DashScopeAPIResponse,
@@ -148,7 +147,7 @@ def fetch(
148147
workspace=workspace,
149148
**kwargs,
150149
)
151-
except (asyncio.TimeoutError, aiohttp.ClientConnectorError) as e:
150+
except (requests.Timeout, requests.ConnectionError) as e:
152151
logger.debug(e)
153152
try_count += 1
154153
if try_count <= Transcription.MAX_QUERY_TRY_COUNT:
@@ -230,7 +229,7 @@ def _launch_request(
230229
workspace=workspace,
231230
**kwargs,
232231
)
233-
except (asyncio.TimeoutError, aiohttp.ClientConnectorError) as e:
232+
except (requests.Timeout, requests.ConnectionError) as e:
234233
logger.debug(e)
235234
try_count += 1
236235
if try_count <= Transcription.MAX_QUERY_TRY_COUNT:

dashscope/audio/qwen_asr/qwen_transcription.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
# -*- coding: utf-8 -*-
22
# Copyright (c) Alibaba, Inc. and its affiliates.
33

4-
import asyncio
54
import time
65
from typing import Union
76

8-
import aiohttp
7+
import requests
98

109
from dashscope.api_entities.dashscope_response import (
1110
DashScopeAPIResponse,
@@ -108,7 +107,7 @@ def fetch(
108107
workspace=workspace,
109108
**kwargs,
110109
)
111-
except (asyncio.TimeoutError, aiohttp.ClientConnectorError) as e:
110+
except (requests.Timeout, requests.ConnectionError) as e:
112111
logger.debug(e)
113112
try_count += 1
114113
if try_count <= QwenTranscription.MAX_QUERY_TRY_COUNT:
@@ -186,7 +185,7 @@ def _launch_request(
186185
workspace=workspace,
187186
**kwargs,
188187
)
189-
except (asyncio.TimeoutError, aiohttp.ClientConnectorError) as e:
188+
except (requests.Timeout, requests.ConnectionError) as e:
190189
logger.debug(e)
191190
try_count += 1
192191
if try_count <= QwenTranscription.MAX_QUERY_TRY_COUNT:

0 commit comments

Comments
 (0)