awslabs / awslabs/agentcore-samples
Amazon Bedrock AgentCore Samples - [UnicodeDecodeError: 'charmap' codec can't decode byte 0x81 in position 14: character maps to <undefined>]
- Dominant language
- Python
- Stars
- 3.4k
- Forks
- 1.3k
- Avg merge
- 1d 22h
- Merged PRs (30d)
- 30
Description
**Describe the bug**
I am testing below notebook on windows VSCode.
_https://github.com/himallik/amazon-bedrock-agentcore-samples/blob/main/01-tutorials/01-AgentCore-runtime/01-hosting-agent/02-langgraph-with-bedrock-model/runtime_with_langgraph_and_bedrock_models.ipynb
It consistently throws the below error
_---------------------------------------------------------------------------
UnicodeDecodeError Traceback (most recent call last)
Cell In[8], [line 1](vscode-notebook-cell:?execution_count=8&line=1)
----> [1](vscode-notebook-cell:?execution_count=8&line=1) launch_result = agentcore_runtime.launch()
2 launch_result
File c:\Python313\Lib\site-packages\bedrock_agentcore_starter_toolkit\notebook\runtime\bedrock_agentcore.py:130, in Runtime.launch(self, local, push_ecr, env_vars)
127 if not self._config_path:
128 raise ValueError("Must configure before launching. Call .configure() first.")
--> [130](file:///C:/Python313/Lib/site-packages/bedrock_agentcore_starter_toolkit/notebook/runtime/bedrock_agentcore.py:130) result =_ launch_bedrock_agentcore(self._config_path, local=local, push_ecr_only=push_ecr, env_vars=env_vars)
132 if result.mode == "cloud":
133 log.info("Deployed to cloud: %s", result.agent_arn)
File c:\Python313\Lib\site-packages\bedrock_agentcore_starter_toolkit\operations\runtime\launch.py:58, in launch_bedrock_agentcore(config_path, agent_name, local, push_ecr_only, env_vars)
55 tag = f"bedrock_agentcore-{bedrock_agentcore_name}:latest"
57 # Step 1: Build Docker image
---> [58](file:///C:/Python313/Lib/site-packages/bedrock_agentcore_starter_toolkit/operations/runtime/launch.py:58) success, output = runtime.build(build_dir, tag)
59 if not success:
60 error_lines = output[-10:] if len(output) > 10 else output
File c:\Python313\Lib\site-packages\bedrock_agentcore_starter_toolkit\utils\runtime\container.py:205, in ContainerRuntime.build(self, dockerfile_dir, tag, platform)
202 cmd.extend(["--platform", build_platform])
203 cmd.append(str(dockerfile_dir))
--> [205](file:///C:/Python313/Lib/site-packages/bedrock_agentcore_starter_toolkit/utils/runtime/container.py:205) return self._execute_command(cmd)
...
File c:\Python313\Lib\encodings\cp1252.py:23, in IncrementalDecoder.decode(self, input, final)
22 def decode(self, input, final=False):
---> [23](file:///C:/Python313/Lib/encodings/cp1252.py:23) return codecs.charmap_decode(input,self.errors,decoding_table)[0]
UnicodeDecodeError: 'charmap' codec can't decode byte 0x81 in position 14: character maps to _
**To Reproduce**
Steps to reproduce the behavior (or some version of this):
Setup credentials and run the notebook.
Adding the below two lines to generated Dockerfile helps fix the issue. agentcore_runtime.configure() call has to automatically include these two lines in Dockerfile
ENV PYTHONIOENCODING=utf8 #this one line is enough, I think.
ENV LANG=C.UTF-8
ENV LC_ALL=C.UTF-8
ENV LANGUAGE=C.UTF-8
**Expected behavior**
It should run without errors
**Screenshots**
If applicable, add screenshots to help explain your problem.
**! Additional context !**
Contributor guide
Research direction
Start with the notebook 01-tutorials/01-AgentCore-runtime/01-hosting-agent/02-langgraph-with-bedrock-model/runtime_with_langgraph_and_bedrock_models.ipynb and trace Runtime.launch through operations/runtime/launch.py to utils/runtime/container.py. Reproduce the Windows failure, inspect how the generated Dockerfile and command output are decoded, and verify that the notebook launches without UnicodeDecodeError.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- docker, jupyter-notebook, python
- Domain
- devops, infrastructure
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 38/100