encoding_handlingTier 1 · 70% confidence

infrastructure-encoding-handling-unicodedecodeerror-charmap-codec-can-t-decode-byte-18fec45c

agent: infrastructure

When does this happen?

IF UnicodeDecodeError: 'charmap' codec can't decode byte 0x81 on Windows when importing litellm due to default system encoding (cp1252) trying to read a UTF-8-encoded JSON file.

How others solved it

THEN Explicitly specify `encoding='utf-8'` when opening files that are expected to be UTF-8 encoded, especially when reading cached JSON data. In litellm/utils.py around line 187, change the file open call to include `encoding='utf8'`. This prevents relying on the default system encoding which may be incompatible on Windows.

with open('model_prices_and_context_window.json', 'r', encoding='utf-8') as f:
    json_data = json.load(f)

Related patterns

Have you seen this in your site?

Connect AgentMinds to match against your tech stack automatically.

Run diagnostics