Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion src/strands_tools/http_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -796,7 +796,24 @@ def http_request(tool: ToolUse, **kwargs: Any) -> ToolResult:
if tool_input.get("streaming", False):
content = stream_response(response)
else:
content = response.text
# Get encoding from Content-Type header or detect it
encoding = None
content_type = response.headers.get("Content-Type", "")

if "charset=" in content_type:
encoding = content_type.split("charset=")[-1].split(";")[0].strip()

# If encoding not specified in headers, let requests try to detect it
# or use 'utf-8' as a fallback for better handling of Chinese and other non-ASCII text
if not encoding:
# Try to use the encoding detected by requests
if hasattr(response, "encoding") and isinstance(response.encoding, str):
encoding = response.encoding if response.encoding != "ISO-8859-1" else "utf-8"
else:
encoding = "utf-8" # Default fallback if encoding is not a string

# Decode the content with the determined encoding
content = response.content.decode(encoding, errors="replace")

# Format and display the response
response_panel = format_response_preview(response, content, metrics if metrics is not None else None)
Expand Down
2 changes: 1 addition & 1 deletion src/strands_tools/memory.py
Original file line number Diff line number Diff line change
Expand Up @@ -583,7 +583,7 @@ def memory(
next_token: Token for pagination in 'list' or 'retrieve' action (optional).
query: The search query for semantic search (required for 'retrieve' action).
min_score: Minimum relevance score threshold (0.0-1.0) for 'retrieve' action. Default is 0.4.
region_name: Optional AWS region name. If not provided, will use the AWS_REGION env variable.
region_name: Optional AWS region name. If not provided, will use the AWS_REGION env variable.
If AWS_REGION is not specified, it will default to us-west-2.

Returns:
Expand Down