Skip to content

Commit 3aa4053

Browse files
zhansheng.lzsclaude
andcommitted
Fix OSS URL wrapping and async cancel/list issues
- Use typer.echo for OSS URL output to avoid rich Console line-wrapping at 80 cols in CI - Fix async cancel to use POST instead of GET - Fix async list to return full JSON response matching sync behavior Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent b2fa270 commit 3aa4053

2 files changed

Lines changed: 37 additions & 15 deletions

File tree

dashscope/cli/oss.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,4 +78,5 @@ def upload(
7878
if not oss_url:
7979
error(f"Failed to upload file: {file_path}")
8080

81-
success(f"Uploaded oss url: {oss_url}")
81+
success("Uploaded oss url:")
82+
typer.echo(oss_url)

dashscope/client/base_api.py

Lines changed: 35 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,7 @@ async def cancel(
273273
url = _normalization_url(base_url, "tasks", task_id, "cancel")
274274
kwargs = cls._handle_kwargs(api_key, workspace, **kwargs)
275275
kwargs["base_address"] = url
276+
kwargs["http_method"] = HTTPMethod.POST
276277
if not api_key:
277278
api_key = get_default_api_key()
278279
request = _build_api_request(
@@ -324,6 +325,8 @@ async def list(
324325
Returns:
325326
DashScopeAPIResponse: The response data.
326327
"""
328+
import aiohttp # pylint: disable=import-outside-toplevel
329+
327330
base_url = kwargs.pop("base_address", None)
328331
url = _normalization_url(base_url, "tasks")
329332
params = {"page_no": page_no, "page_size": page_size}
@@ -339,22 +342,40 @@ async def list(
339342
params["region"] = region
340343
if status is not None:
341344
params["status"] = status
342-
kwargs = cls._handle_kwargs(api_key, workspace, **kwargs)
343-
kwargs["base_address"] = url
344345
if not api_key:
345346
api_key = get_default_api_key()
346-
request = _build_api_request(
347-
model_name,
348-
"",
349-
"",
350-
"",
351-
"",
352-
api_key=api_key,
353-
is_service=False,
354-
extra_url_parameters=params,
355-
**kwargs,
356-
)
357-
return await cls._handle_request(request)
347+
headers = {
348+
**_workspace_header(workspace),
349+
**default_headers(api_key),
350+
}
351+
async with aiohttp.ClientSession() as session:
352+
response = await session.get(
353+
url,
354+
params=params,
355+
headers=headers,
356+
)
357+
if response.status == HTTPStatus.OK:
358+
json_content = await response.json()
359+
request_id = ""
360+
if "request_id" in json_content:
361+
request_id = json_content["request_id"]
362+
json_content.pop("request_id")
363+
return DashScopeAPIResponse(
364+
request_id=request_id,
365+
status_code=response.status,
366+
code=None, # type: ignore[arg-type]
367+
output=json_content,
368+
usage=None,
369+
message="",
370+
)
371+
else:
372+
from dashscope.common.utils import ( # pylint: disable=import-outside-toplevel # noqa: E501
373+
_handle_aiohttp_failed_response,
374+
)
375+
376+
return await _handle_aiohttp_failed_response(
377+
response,
378+
)
358379

359380
@classmethod
360381
async def fetch(

0 commit comments

Comments
 (0)