aws / aws/bedrock-agentcore-starter-toolkit
[BUG] UnicodeEncodeError on Windows: write_text() missing UTF-8 encoding in base_feature.py
- Dominant language
- Python
- Stars
- 508
- Forks
- 155
- Avg merge
- 8h 50m
- Merged PRs (30d)
- 4
Description
**Describe the bug**
`agentcore` create fails on Windows with a **UnicodeEncodeError** when writing template files that contain Unicode emoji characters. The library's `base_feature.py` uses `Path.write_text()` without specifying UTF-8 encoding, causing it to default to Windows' cp1252 encoding which cannot handle Unicode emojis.
**To Reproduce**
Steps to reproduce the behavior:
1. Install package: `pip install bedrock-agentcore-starter-toolkit`
2. Run command: `agentcore create`
3. Select options:
- Agent framework: Strands Agents SDK
- Model provider: Amazon Bedrock
- Memory: Short-term memory
7. See error when the toolkit tries to write template files containing emoji characters
**Expected behavior**
The `agentcore `create command should successfully create the project structure and write all template files, including those containing Unicode emoji characters (like 📊 in the template).
**Error Output**
```
UnicodeEncodeError: 'charmap' codec can't encode character '\U0001f4ca' in position 3612: character maps to
```
Full traceback:
```
File: bedrock_agentcore_starter_toolkit\create\features\base_feature.py:104dest.write_text(rendered_content)File: pathlib\__init__.py:810 in write_textreturn f.write(data)File: encodings\cp1252.py:19 in encodereturn codecs.charmap_encode(input,self.errors,encoding_table)[0]
```
The error occurs because:
- Line 982: encoding = 'locale' (defaults to cp1252 on Windows)
- Line 986: mode='w' encoding='cp1252' (Windows default encoding)
- The template file contains emoji character \U0001f4ca (📊) at position 3612
**Environment:**
- OS: Windows 10 (Build 26200)
- Python version: 3.14 (pythoncore-3.14-64)
- Package version: 0.2.5
- Installation method: pip
**Root Cause**
The bug is in `bedrock_agentcore_starter_toolkit/create/features/base_feature.py ` at line 104:
Current code:
```
dest.write_text(rendered_content)
```
Problem: When encoding is not specified, `Path.write_text()` defaults to the system locale encoding. On Windows, this is typically cp1252, which cannot encode Unicode emoji characters.
Template file containing emoji:
- File: `create/features/strands/templates/runtime_only/common/main.py.j2`
- Line 101:` parts.append(f"## 📊 Result:\n{str(result)}")`
**Proposed Fix**
Change line 104 in base_feature.py from:
```
dest.write_text(rendered_content)
```
To:
```
dest.write_text(rendered_content, encoding='utf-8')
```
This ensures all template files are written with UTF-8 encoding, which supports Unicode characters including emojis.
**Additional context**
- The issue only affects Windows systems with default cp1252 encoding
- Linux/macOS systems typically use UTF-8 by default and may not encounter this issue
- The emoji character is in the library's own template file, not user-generated content
- This is a cross-platform compatibility issue that should be fixed in the library code
Contributor guide
Research direction
Start in bedrock_agentcore_starter_toolkit/create/features/base_feature.py at the template-writing call, then inspect create/features/strands/templates/runtime_only/common/main.py.j2 and its Unicode character. Reproduce `agentcore create` on Windows with the reported options and verify that the generated project is written successfully with the expected Unicode content.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- cli
- Issue type
- Bug
- Difficulty
- 1/5
- Estimated time
- Under an hour
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 50/100