From d983305f9042f0183d6c0634ecbb992d7b6fed01 Mon Sep 17 00:00:00 2001 From: "zhansheng.lzs" Date: Thu, 18 Jun 2026 14:58:01 +0800 Subject: [PATCH 1/3] fix: downgrade redundant logger.error(e) to debug in audio modules The SDK's exception handlers were logging exceptions at error level before re-raising, causing duplicate logs in user applications. Following PR #68 discussion, downgrade to debug level across audio/asr, audio/qwen_asr, and audio/tts_v2 modules. Co-Authored-By: Claude Opus 4.7 --- dashscope/audio/asr/recognition.py | 2 +- dashscope/audio/asr/transcription.py | 4 ++-- dashscope/audio/asr/translation_recognizer.py | 2 +- dashscope/audio/asr/vocabulary.py | 2 +- dashscope/audio/qwen_asr/qwen_transcription.py | 4 ++-- dashscope/audio/tts_v2/enrollment.py | 2 +- 6 files changed, 8 insertions(+), 8 deletions(-) diff --git a/dashscope/audio/asr/recognition.py b/dashscope/audio/asr/recognition.py index 8b988f6..e4b1ea1 100644 --- a/dashscope/audio/asr/recognition.py +++ b/dashscope/audio/asr/recognition.py @@ -444,7 +444,7 @@ def call( # type: ignore[override] # noqa: E501 f.close() self._stop_stream_timestamp = time.time() * 1000 except Exception as e: - logger.error(e) + logger.debug(e) raise e if not self._stream_data.empty(): diff --git a/dashscope/audio/asr/transcription.py b/dashscope/audio/asr/transcription.py index cf8ce4d..32b5bbd 100644 --- a/dashscope/audio/asr/transcription.py +++ b/dashscope/audio/asr/transcription.py @@ -149,7 +149,7 @@ def fetch( **kwargs, ) except (asyncio.TimeoutError, aiohttp.ClientConnectorError) as e: - logger.error(e) + logger.debug(e) try_count += 1 if try_count <= Transcription.MAX_QUERY_TRY_COUNT: time.sleep(2) @@ -231,7 +231,7 @@ def _launch_request( **kwargs, ) except (asyncio.TimeoutError, aiohttp.ClientConnectorError) as e: - logger.error(e) + logger.debug(e) try_count += 1 if try_count <= Transcription.MAX_QUERY_TRY_COUNT: time.sleep(2) diff --git a/dashscope/audio/asr/translation_recognizer.py b/dashscope/audio/asr/translation_recognizer.py index f677dd2..06ba8fb 100644 --- a/dashscope/audio/asr/translation_recognizer.py +++ b/dashscope/audio/asr/translation_recognizer.py @@ -582,7 +582,7 @@ def call( # type: ignore[override] f.close() self._stop_stream_timestamp = time.time() * 1000 except Exception as e: - logger.error(e) + logger.debug(e) raise e if not self._stream_data.empty(): diff --git a/dashscope/audio/asr/vocabulary.py b/dashscope/audio/asr/vocabulary.py index 8fd2ce8..31d80ee 100644 --- a/dashscope/audio/asr/vocabulary.py +++ b/dashscope/audio/asr/vocabulary.py @@ -69,7 +69,7 @@ def __call_with_input(self, input): # pylint: disable=redefined-builtin **self._kwargs, ) except (asyncio.TimeoutError, aiohttp.ClientConnectorError) as e: - logger.error(e) + logger.debug(e) try_count += 1 if try_count <= VocabularyService.MAX_QUERY_TRY_COUNT: time.sleep(2) diff --git a/dashscope/audio/qwen_asr/qwen_transcription.py b/dashscope/audio/qwen_asr/qwen_transcription.py index 859f0fc..5d6e7a1 100644 --- a/dashscope/audio/qwen_asr/qwen_transcription.py +++ b/dashscope/audio/qwen_asr/qwen_transcription.py @@ -109,7 +109,7 @@ def fetch( **kwargs, ) except (asyncio.TimeoutError, aiohttp.ClientConnectorError) as e: - logger.error(e) + logger.debug(e) try_count += 1 if try_count <= QwenTranscription.MAX_QUERY_TRY_COUNT: time.sleep(2) @@ -187,7 +187,7 @@ def _launch_request( **kwargs, ) except (asyncio.TimeoutError, aiohttp.ClientConnectorError) as e: - logger.error(e) + logger.debug(e) try_count += 1 if try_count <= QwenTranscription.MAX_QUERY_TRY_COUNT: time.sleep(2) diff --git a/dashscope/audio/tts_v2/enrollment.py b/dashscope/audio/tts_v2/enrollment.py index 9a728c3..74c5f3b 100644 --- a/dashscope/audio/tts_v2/enrollment.py +++ b/dashscope/audio/tts_v2/enrollment.py @@ -72,7 +72,7 @@ def __call_with_input( # pylint: disable=redefined-builtin **self._kwargs, ) except (asyncio.TimeoutError, aiohttp.ClientConnectorError) as e: - logger.error(e) + logger.debug(e) try_count += 1 if try_count <= VoiceEnrollmentService.MAX_QUERY_TRY_COUNT: time.sleep(2) From cfb77f217b8fb841b84428cf1f67ce7ad81430eb Mon Sep 17 00:00:00 2001 From: "zhansheng.lzs" Date: Thu, 18 Jun 2026 15:16:26 +0800 Subject: [PATCH 2/3] fix: use bare raise and correct exception types in audio modules - Change raise e to bare raise in recognition.py and translation_recognizer.py to preserve original tracebacks - Fix vocabulary.py and enrollment.py catching asyncio/aiohttp exceptions despite using sync requests-based BaseApi; switch to requests.Timeout and requests.ConnectionError Co-Authored-By: Claude Opus 4.7 --- dashscope/audio/asr/recognition.py | 2 +- dashscope/audio/asr/translation_recognizer.py | 2 +- dashscope/audio/asr/vocabulary.py | 5 ++--- dashscope/audio/tts_v2/enrollment.py | 5 ++--- 4 files changed, 6 insertions(+), 8 deletions(-) diff --git a/dashscope/audio/asr/recognition.py b/dashscope/audio/asr/recognition.py index e4b1ea1..7dc7bc4 100644 --- a/dashscope/audio/asr/recognition.py +++ b/dashscope/audio/asr/recognition.py @@ -445,7 +445,7 @@ def call( # type: ignore[override] # noqa: E501 self._stop_stream_timestamp = time.time() * 1000 except Exception as e: logger.debug(e) - raise e + raise if not self._stream_data.empty(): self._running = True diff --git a/dashscope/audio/asr/translation_recognizer.py b/dashscope/audio/asr/translation_recognizer.py index 06ba8fb..2f3405c 100644 --- a/dashscope/audio/asr/translation_recognizer.py +++ b/dashscope/audio/asr/translation_recognizer.py @@ -583,7 +583,7 @@ def call( # type: ignore[override] self._stop_stream_timestamp = time.time() * 1000 except Exception as e: logger.debug(e) - raise e + raise if not self._stream_data.empty(): self._running = True diff --git a/dashscope/audio/asr/vocabulary.py b/dashscope/audio/asr/vocabulary.py index 31d80ee..9e8510b 100644 --- a/dashscope/audio/asr/vocabulary.py +++ b/dashscope/audio/asr/vocabulary.py @@ -1,11 +1,10 @@ # -*- coding: utf-8 -*- # Copyright (c) Alibaba, Inc. and its affiliates. -import asyncio import time from typing import List -import aiohttp +import requests from dashscope.client.base_api import BaseApi from dashscope.common.constants import ApiProtocol, HTTPMethod @@ -68,7 +67,7 @@ def __call_with_input(self, input): # pylint: disable=redefined-builtin workspace=self._workspace, **self._kwargs, ) - except (asyncio.TimeoutError, aiohttp.ClientConnectorError) as e: + except (requests.Timeout, requests.ConnectionError) as e: logger.debug(e) try_count += 1 if try_count <= VocabularyService.MAX_QUERY_TRY_COUNT: diff --git a/dashscope/audio/tts_v2/enrollment.py b/dashscope/audio/tts_v2/enrollment.py index 74c5f3b..239606a 100644 --- a/dashscope/audio/tts_v2/enrollment.py +++ b/dashscope/audio/tts_v2/enrollment.py @@ -1,11 +1,10 @@ # -*- coding: utf-8 -*- # Copyright (c) Alibaba, Inc. and its affiliates. -import asyncio import time from typing import List -import aiohttp +import requests from dashscope.client.base_api import BaseApi from dashscope.common.constants import ApiProtocol, HTTPMethod @@ -71,7 +70,7 @@ def __call_with_input( # pylint: disable=redefined-builtin workspace=self._workspace, **self._kwargs, ) - except (asyncio.TimeoutError, aiohttp.ClientConnectorError) as e: + except (requests.Timeout, requests.ConnectionError) as e: logger.debug(e) try_count += 1 if try_count <= VoiceEnrollmentService.MAX_QUERY_TRY_COUNT: From b2bc3383e05ab40532d8da89fc57bd42ec5c9d98 Mon Sep 17 00:00:00 2001 From: "zhansheng.lzs" Date: Thu, 18 Jun 2026 15:23:48 +0800 Subject: [PATCH 3/3] 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 --- dashscope/audio/asr/transcription.py | 7 +++---- dashscope/audio/qwen_asr/qwen_transcription.py | 7 +++---- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/dashscope/audio/asr/transcription.py b/dashscope/audio/asr/transcription.py index 32b5bbd..88631ac 100644 --- a/dashscope/audio/asr/transcription.py +++ b/dashscope/audio/asr/transcription.py @@ -1,11 +1,10 @@ # -*- coding: utf-8 -*- # Copyright (c) Alibaba, Inc. and its affiliates. -import asyncio import time from typing import List, Union -import aiohttp +import requests from dashscope.api_entities.dashscope_response import ( DashScopeAPIResponse, @@ -148,7 +147,7 @@ def fetch( workspace=workspace, **kwargs, ) - except (asyncio.TimeoutError, aiohttp.ClientConnectorError) as e: + except (requests.Timeout, requests.ConnectionError) as e: logger.debug(e) try_count += 1 if try_count <= Transcription.MAX_QUERY_TRY_COUNT: @@ -230,7 +229,7 @@ def _launch_request( workspace=workspace, **kwargs, ) - except (asyncio.TimeoutError, aiohttp.ClientConnectorError) as e: + except (requests.Timeout, requests.ConnectionError) as e: logger.debug(e) try_count += 1 if try_count <= Transcription.MAX_QUERY_TRY_COUNT: diff --git a/dashscope/audio/qwen_asr/qwen_transcription.py b/dashscope/audio/qwen_asr/qwen_transcription.py index 5d6e7a1..f731ff9 100644 --- a/dashscope/audio/qwen_asr/qwen_transcription.py +++ b/dashscope/audio/qwen_asr/qwen_transcription.py @@ -1,11 +1,10 @@ # -*- coding: utf-8 -*- # Copyright (c) Alibaba, Inc. and its affiliates. -import asyncio import time from typing import Union -import aiohttp +import requests from dashscope.api_entities.dashscope_response import ( DashScopeAPIResponse, @@ -108,7 +107,7 @@ def fetch( workspace=workspace, **kwargs, ) - except (asyncio.TimeoutError, aiohttp.ClientConnectorError) as e: + except (requests.Timeout, requests.ConnectionError) as e: logger.debug(e) try_count += 1 if try_count <= QwenTranscription.MAX_QUERY_TRY_COUNT: @@ -186,7 +185,7 @@ def _launch_request( workspace=workspace, **kwargs, ) - except (asyncio.TimeoutError, aiohttp.ClientConnectorError) as e: + except (requests.Timeout, requests.ConnectionError) as e: logger.debug(e) try_count += 1 if try_count <= QwenTranscription.MAX_QUERY_TRY_COUNT: