UnicodeEncodeError 🐍 Python

UnicodeEncodeError: 'charmap' codec can't encode character '\u2192'

Python tried to write text in an encoding that can’t represent some characters — common in Windows consoles and files opened without encoding.

Seen on: Python

Meaning

Windows console/legacy code pages (cp1252, charmap) can’t print many Unicode characters. Writing files without encoding= uses the platform default.

Common causes

  • Printing Unicode to a Windows console
  • open(..., "w") without encoding="utf-8"
  • Old ASCII-only locale on Linux servers (LANG=C)

⚡ Quick fix

  1. Open files with encoding="utf-8"
  2. Set PYTHONIOENCODING=utf-8 or PYTHONUTF8=1
  3. Use a UTF-8 terminal / chcp 65001

Detailed fix by platform

Windows

  1. set PYTHONUTF8=1 (or set it in system environment variables)

How to diagnose

  1. Destination — Console or file?
  2. Encoding — Which codec is named?

🧠 Still stuck? Analyze your error

Paste the full message, response headers or stack trace — we'll detect the platform and point to the most likely cause.