RestApiTool crashes the agent run on a non-UTF-8 error response body (UnicodeDecodeError in the HTTPStatusError handler)
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 2/5
- Thời gian dự kiến
- 1-3 giờ
- Mức phù hợp với người mới
- 78/100
Hướng nghiên cứu
Bắt đầu tại RestApiTool.call() và so sánh HTTPStatusError handler với nhánh thành công không phải JSON ở vài dòng bên dưới. Thêm regression test được đề cập bằng cách sử dụng response không phải UTF-8 đã được mock, sau đó xác minh rằng tool trả về error dict 404 như mong đợi và agent run không bị lỗi.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
🔴 Required Information
Describe the Bug:
When an API call fails, RestApiTool.call() builds the error message for the model with:
except httpx.HTTPStatusError:
error_details = response.content.decode("utf-8")
That forces UTF-8 regardless of the charset the server declares. A non-UTF-8 error body raises UnicodeDecodeError, for example a Latin-1/Windows-1252 page from an older ERP or IIS server, a message with accented characters, or a binary body. The exception is raised inside the except handler, so the sibling except ValueError can't catch it. It propagates out of the tool and ends the whole agent run, so the model never sees the HTTP error it could have recovered from.
Steps to Reproduce:
pip install google-adk(reproduced onmain@ 3f4bb8fa).- Run the script below: a real
RunnerplusLlmAgentplusOpenAPIToolset, with a mocked model and anhttpx.MockTransportbackend that answers404with atext/plain; charset=iso-8859-1body.
Expected Behavior:
The tool returns its usual error dict, decoded with the declared charset:
... Execution Error: Status Code: 404, Commande introuvable : échec
Observed Behavior:
RUN FAILED: UnicodeDecodeError - 'utf-8' codec can't decode byte 0xe9 in position 23: invalid continuation byte
Environment Details:
- ADK Library Version (pip show google-adk):
main@ 3f4bb8fa - Desktop OS: Windows 11
- Python Version (python -V): 3.12.10
Model Information:
- Are you using LiteLLM: No
- Which model is being used: N/A (mocked model; the bug is in response handling)
🟡 Optional Information
Minimal Reproduction Code:
import asyncio
import httpx
from google.adk.agents.llm_agent import LlmAgent
from google.adk.models.base_llm import BaseLlm
from google.adk.models.llm_response import LlmResponse
from google.adk.runners import InMemoryRunner
from google.adk.tools.openapi_tool.openapi_spec_parser.openapi_toolset import OpenAPIToolset
from google.genai import types
spec = {
"openapi": "3.0.0",
"info": {"title": "Legacy ERP", "version": "1"},
"servers": [{"url": "https://erp.example.com"}],
"paths": {"/orders/{id}": {"get": {
"operationId": "getOrder",
"parameters": [{"name": "id", "in": "path", "required": True, "schema": {"type": "string"}}],
"responses": {"200": {"description": "ok"}},
}}},
}
def handler(request: httpx.Request):
# A legacy server answering in Windows-1252 / Latin-1, as it declares.
return httpx.Response(
404,
content="Commande introuvable : échec".encode("latin-1"),
headers={"content-type": "text/plain; charset=iso-8859-1"},
)
class FakeModel(BaseLlm):
model: str = "fake"
calls: int = 0
async def generate_content_async(self, llm_request, stream=False):
self.calls += 1
part = (types.Part.from_function_call(name="get_order", args={"id": "A-42"})
if self.calls == 1 else types.Part.from_text(text="done"))
yield LlmResponse(content=types.Content(role="model", parts=[part]))
agent = LlmAgent(
name="erp_agent",
model=FakeModel(),
tools=[OpenAPIToolset(
spec_dict=spec,
httpx_client_factory=lambda: httpx.AsyncClient(transport=httpx.MockTransport(handler)),
)],
)
async def main():
runner = InMemoryRunner(agent=agent)
session = await runner.session_service.create_session(app_name=runner.app_name, user_id="u")
try:
async for event in runner.run_async(
user_id="u", session_id=session.id,
new_message=types.Content(role="user", parts=[types.Part(text="order A-42?")])):
for fr in event.get_function_responses():
print("function_response:", fr.response)
except Exception as e:
print("RUN FAILED:", type(e).__name__, "-", e)
asyncio.run(main())
Suggested fix: use response.text, which is what the non-JSON success path a few lines below already uses. It decodes with the response's declared charset and replaces undecodable bytes instead of raising. I have a PR ready with a test.
How often has this issue occurred?:
- Always (100%): any non-UTF-8 error body.
- Ngôn ngữ chính
- Python
- Star
- 21.6k
- Fork
- 4k
- Merge trung bình
- 13 giờ 49 phút
- Pull request đã merge (30 ngày)
- 10
Hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của google/adk-python
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
google/adk-python#7217 · 1 bình luận ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 86/100
google/adk-python#7205 · 1 bình luận ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
google/adk-python#7196 · 1 bình luận ·
-
eval request clarification
Độ khó 1/5 1-3 giờ Mức phù hợp với người mới 86/100
google/adk-python#7146 · 2 bình luận · 1 người được giao ·
-
mcp
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 88/100
google/adk-python#7144 · 1 bình luận · 1 người được giao ·
Tất cả issue của google/adk-python
Issue tương tự
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 86/100
zostera/django-bootstrap4#894 ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
use-agent-os/agent-os#3276 ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 88/100
zephyrproject-rtos/zephyr#119726 ·
-
area/auth bug comp/agent P3 platform/discord type/security
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 88/100
NousResearch/hermes-agent#117848 ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
zilliztech/memsearch#759 ·