agents-cli icon indicating copy to clipboard operation
agents-cli copied to clipboard

UnicodeEncodeError crashes `setup` on Windows before any work starts (logo uses Unicode block chars on cp1252 console)

Open lenintorresact opened this issue 6 months ago • 10 comments

Analysis below was done by Claude (Anthropic, via Claude Code) while debugging this on my machine. Filing as-is — not claiming credit for the investigation.

What happened?

On a fresh Windows 11 install, uvx google-agents-cli setup crashes with UnicodeEncodeError: 'charmap' codec can't encode characters in position 1-3 before reaching any setup logic. The crash happens inside _print_logo() at setup/cmd_setup.py:41 because the logo is drawn with Unicode block characters (█ ▀ ▄, U+2588 / U+2580 / U+2584), and Python on Windows defaults to writing stdout through the legacy cp1252 codepage, which has no glyphs for those characters.

This is independent of #14. After working around #14 (or installing without gcloud needing to be called), this bug still prevents setup from running unless the user happens to know to set PYTHONUTF8=1. For a "getting started" command, that's a hard wall on Windows.

Steps to Reproduce

  1. Fresh Windows 11 PowerShell session, no PYTHONUTF8 set.
  2. uvx google-agents-cli setup
  3. Crash before the logo prints, before any setup work begins.

What did you expect to happen?

setup should print the logo (or a non-fancy fallback) and proceed.

Workaround

$env:PYTHONUTF8 = "1"
uvx google-agents-cli setup

or permanently: [Environment]::SetEnvironmentVariable("PYTHONUTF8", "1", "User").

Suggested fix

Two options, in order of preference:

1. Reconfigure stdio at CLI entry. Near the top of main.py, before any click.secho runs:

import sys
if sys.platform == "win32":
    sys.stdout.reconfigure(encoding="utf-8", errors="replace")
    sys.stderr.reconfigure(encoding="utf-8", errors="replace")

This fixes the logo and any future Unicode-bearing output. The codebase already prints non-ASCII characters in other places (e.g. the ⚠️ warning emoji at auth.py:67, ─ separators throughout) that would crash the same way on a cp1252 console.

2. Guard _print_logo with a try/except + ASCII fallback. Less robust — only protects this one site, leaves the other Unicode call sites as latent crashes.

Stack trace

agents-cli v0.1.3
Traceback (most recent call last):
  File "...\google\agents\cli\setup\cmd_setup.py", line 41, in _print_logo
    click.secho(
        " █▀█ █▀▀ █▀▀ █▄ █ ▀█▀ █▀   █▀▀ █  █",
        fg="blue",
        bold=True,
    )
  File "...\click\termui.py", line 698, in secho
    return echo(message, file=file, nl=nl, err=err, color=color)
  File "...\click\utils.py", line 324, in echo
    file.write(out)
  File "...\Lib\encodings\cp1252.py", line 19, in encode
    return codecs.charmap_encode(input, self.errors, encoding_table)[0]
UnicodeEncodeError: 'charmap' codec can't encode characters in position 1-3: character maps to <undefined>

Client information

  • CLI: agents-cli v0.1.3
  • OS: Windows 11 (10.0.26200)
  • Python: 3.14 (uvx-managed)
  • Console: PowerShell 5.1, default cp1252 codepage
  • Install: uvx google-agents-cli setup

lenintorresact avatar May 10 '26 05:05 lenintorresact

Thank you for your feedback! We'll look into this.

Internal tracking: b/511716240

If you are able, can you please clarify if this occurs only on 0.1.3, or on previous versions of agents-cli as well?

sushicw avatar May 11 '26 17:05 sushicw

Hello,

I have not tried other versions, sorry

El lun, 11 may 2026 a las 12:40, Chris Wilson @.***>) escribió:

sushicw left a comment (google/agents-cli#15) https://github.com/google/agents-cli/issues/15#issuecomment-4423256609

Thank you for your feedback! We'll look into this.

Internal tracking: b/511716240

If you are able, can you please clarify if this occurs only on 0.1.3, or on previous versions of agents-cli as well?

— Reply to this email directly, view it on GitHub https://github.com/google/agents-cli/issues/15#issuecomment-4423256609, or unsubscribe https://github.com/notifications/unsubscribe-auth/BJSM4SUGOCDU5OKZT743A7342IGBRAVCNFSM6AAAAACYXY5S36VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHM2DIMRTGI2TMNRQHE . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

You are receiving this because you authored the thread.Message ID: @.***>

Lenin Torres Head of AI (+593-2) 392-3400

@.***

Av. Orellana E9-195 y Av. 6 de Diciembre, Edif. Alisal de Orellana, Of. 804. Quito - Ecuador

www.actuaria.com En Actuaria, actuamos por un mundo mejor con los ​objetivos de desarrollo sostenible. Términos y condiciones - Seguridad de la información

lenintorresact avatar May 11 '26 19:05 lenintorresact

I haven't been able to repro on Powershell so far:

PS C:\Users\crwilson> chcp 1252
Active code page: 1252
PS C:\Users\crwilson> agents-cli setup

 █▀█ █▀▀ █▀▀ █▄ █ ▀█▀ █▀   █▀▀ █  █
 █▀█ █▄█ ██▄ █ ▀█  █  ▄█   █▄▄ █▄ █

 Skills up. Ship faster.

 1. Authentication
 ─────────────────

The proposed fix using sys.stdout.reconfigure is probably a reasonable precaution, regardless, but if possible I would like to be able to reproduce the error so I can confirm the fix works.

Can you please use chcp from your Powershell session to confirm the code page you are using? Mine defaults to 437 and both that and 1252 are working for me.

sushicw avatar May 11 '26 21:05 sushicw

Sure.

[image: image.png]

System info, just in case:

Nombre de host: ACT-165 Nombre del sistema operativo: Microsoft Windows 11 Pro Versión del sistema operativo: 10.0.26200 N/D Compilación 26200 Fabricante del sistema operativo: Microsoft Corporation Configuración del sistema operativo: Estación de trabajo independiente Tipo de compilación del sistema operativo: Multiprocessor Free Propietario registrado: actuaria-local Organización registrada: HP Inc. Id. del producto: 00355-63626-73817-AAOEM Fecha de instalación original: 17/1/2026, 15:18:14 Tiempo de arranque del sistema: 6/5/2026, 14:58:32 Fabricante del sistema: HP Modelo del sistema: HP ProBook 460 16 inch G11 Notebook PC Tipo de sistema: x64-based PC Procesadores: 1 Procesadores instalados. [01]: Intel64 Family 6 Model 170 Stepping 4 GenuineIntel ~1700 Mhz Versión del BIOS: HP W72 Ver. 01.08.02, 8/1/2026 Directorio de Windows: C:\windows Directorio de sistema: C:\windows\system32 Dispositivo de arranque: \Device\HarddiskVolume1 Configuración regional del sistema: es-mx;Español (México) Idioma de entrada: es-mx;Español (México) Zona horaria: (UTC-05:00) Bogotá, Lima, Quito, Rio Branco Memoria física total: 32,220 MB Memoria física disponible: 9,575 MB Memoria virtual: tamaño máximo: 49,628 MB Memoria virtual: disponible: 9,182 MB Memoria virtual: en uso: 40,446 MB Ubicaciones de archivos de página: C:\pagefile.sys Dominio: WORKGROUP Servidor de inicio de sesión: \ACT-165 Revisiones: 7 revisión(es) instaladas. [01]: KB5082417 [02]: KB5050575 [03]: KB5054156 [04]: KB5054273 [05]: KB5071430 [06]: KB5083769 [07]: KB5088467 Tarjetas de red: 4 Tarjetas de interfaz de red instaladas. [01]: Intel(R) Wi-Fi 6E AX211 160MHz Nombre de conexión: Wi-Fi DHCP habilitado: Sí Servidor DHCP: 172.16.24.20 Direcciones IP [01]: 172.16.24.44 [02]: fe80::6236:17c6:b8a8:b4e6 [02]: Realtek PCIe GbE Family Controller Nombre de conexión: Ethernet Estado: Medios desconectados [03]: Fortinet SSL VPN Virtual Ethernet Adapter Nombre de conexión: Ethernet 2 Estado: Medios desconectados [04]: VirtualBox Host-Only Ethernet Adapter Nombre de conexión: Ethernet 4 DHCP habilitado: No

Seguridad basada en virtualización: Estado: En ejecución Propiedades de seguridad requeridas: Compatibilidad con la virtualización base Propiedades de seguridad disponibles: Compatibilidad con la virtualización base Arranque seguro Protección de DMA Código UEFI de solo lectura SMM Security Mitigations 1.0 Control de ejecución basado en el modo Virtualización de APIC Services Configured: Integridad del código reforzada por el hipervisor Services Running: Integridad del código reforzada por el hipervisor App Control for Business policy: Forzado App Control for Business user mode policy: Desactivado Características de seguridad habilitadas: Requisitos Hyper-V: Se detectó un hipervisor. No se mostrarán las características necesarias para Hyper-V.

El lun, 11 may 2026 a las 16:05, Chris Wilson @.***>) escribió:

sushicw left a comment (google/agents-cli#15) https://github.com/google/agents-cli/issues/15#issuecomment-4425187486

I haven't been able to repro on Powershell so far:

PS C:\Users\crwilson> chcp 1252 Active code page: 1252 PS C:\Users\crwilson> agents-cli setup

█▀█ █▀▀ █▀▀ █▄ █ ▀█▀ █▀ █▀▀ █ █ █▀█ █▄█ ██▄ █ ▀█ █ ▄█ █▄▄ █▄ █

Skills up. Ship faster.

  1. Authentication ─────────────────

The proposed fix using sys.stdout.reconfigure is probably a reasonable precaution, regardless, but if possible I would like to be able to repro so I can confirm the fix works.

Can you please use chcp from your Powershell session to confirm the code page you are using? Mine defaults to 437 and both that and 1252 are working for me.

— Reply to this email directly, view it on GitHub https://github.com/google/agents-cli/issues/15#issuecomment-4425187486, or unsubscribe https://github.com/notifications/unsubscribe-auth/BJSM4STAG5R25BXRB47OCTT42I6DDAVCNFSM6AAAAACYXY5S36VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHM2DIMRVGE4DONBYGY . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

You are receiving this because you authored the thread.Message ID: @.***>

Lenin Torres Head of AI (+593-2) 392-3400

@.***

Av. Orellana E9-195 y Av. 6 de Diciembre, Edif. Alisal de Orellana, Of. 804. Quito - Ecuador

www.actuaria.com En Actuaria, actuamos por un mundo mejor con los ​objetivos de desarrollo sostenible. Términos y condiciones - Seguridad de la información

lenintorresact avatar May 11 '26 21:05 lenintorresact

The screenshot didn't attach, but that's OK, just the text output on Powershell should suffice.

Thank you again for your help narrowing this down!

sushicw avatar May 11 '26 23:05 sushicw

Sorry for that.

Here is the output:

PS C:\Users\lenin.torres_actuari\dev\agente-estudio-actuarial\back> chcp Página de códigos activa: 850

El lun, 11 may 2026 a las 18:26, Chris Wilson @.***>) escribió:

sushicw left a comment (google/agents-cli#15) https://github.com/google/agents-cli/issues/15#issuecomment-4425962395

The screenshot didn't attach, but that's OK, just the text output on Powershell should suffice.

Thank you again for your help narrowing this down!

— Reply to this email directly, view it on GitHub https://github.com/google/agents-cli/issues/15#issuecomment-4425962395, or unsubscribe https://github.com/notifications/unsubscribe-auth/BJSM4SWECIMLCLGXLA65VXD42JOQRAVCNFSM6AAAAACYXY5S36VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHM2DIMRVHE3DEMZZGU . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

You are receiving this because you authored the thread.Message ID: @.***>

Lenin Torres Head of AI (+593-2) 392-3400

@.***

Av. Orellana E9-195 y Av. 6 de Diciembre, Edif. Alisal de Orellana, Of. 804. Quito - Ecuador

www.actuaria.com En Actuaria, actuamos por un mundo mejor con los ​objetivos de desarrollo sostenible. Términos y condiciones - Seguridad de la información

lenintorresact avatar May 12 '26 02:05 lenintorresact

Unfortunately I still can't repro the problem. 😕 I can force my Powershell session to fail with UnicodeEncodeError:

PS C:\Users\crwilson> $env:PYTHONLEGACYWINDOWSSTDIO = "1"
PS C:\Users\crwilson> $env:PYTHONIOENCODING = "charmap"
PS C:\Users\crwilson> python -c "import sys; print(' █▀█ █▀▀ █▀▀ █▄ █ ▀█▀ █▀   █▀▀ █  █')"
Traceback (most recent call last):
  File "<string>", line 1, in <module>
    import sys; print(' \u2588\u2580\u2588 \u2588\u2580\u2580 \u2588\u2580\u2580 \u2588\u2584 \u2588 \u2580\u2588\u2580 \u2588\u2580   \u2588\u2580\u2580 \u2588  \u2588')
                ~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Program Files\Python314\Lib\encodings\charmap.py", line 30, in encode
    return codecs.charmap_encode(input, self.errors, self.mapping)[0]
           ~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
UnicodeEncodeError: 'latin-1' codec can't encode characters in position 1-3: ordinal not in range(256)

However, when I run agents-cli, it works fine.

I can at least verify that the sys.stdout.reconfigure mechanism does prevent the above crash, although it's pretty ugly looking:

PS C:\Users\crwilson> python -c "import sys; sys.stdout.reconfigure(encoding='utf-8', errors='replace'); print(' █▀█ █▀▀ █▀▀ █▄ █ ▀█▀ █▀   █▀▀ █  █')"
 ΓûêΓûÇΓûê ΓûêΓûÇΓûÇ ΓûêΓûÇΓûÇ ΓûêΓûä Γûê ΓûÇΓûêΓûÇ ΓûêΓûÇ   ΓûêΓûÇΓûÇ Γûê  Γûê

I'll probably end up submitting the fix anyway, although it would be preferable if I could test it properly!

sushicw avatar May 12 '26 23:05 sushicw

A fix (using reconfigure) will be in the next release.

sushicw avatar May 13 '26 16:05 sushicw

Hello Chris,

Thank you and continue the great work!

El mié, 13 may 2026 a las 11:00, Chris Wilson @.***>) escribió:

sushicw left a comment (google/agents-cli#15) https://github.com/google/agents-cli/issues/15#issuecomment-4442880627

A fix (using reconfigure) will be in the next release.

— Reply to this email directly, view it on GitHub https://github.com/google/agents-cli/issues/15#issuecomment-4442880627, or unsubscribe https://github.com/notifications/unsubscribe-auth/BJSM4SWAHVALFEFNSGEHSBT42SLZ7AVCNFSM6AAAAACYXY5S36VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHM2DINBSHA4DANRSG4 . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

You are receiving this because you authored the thread.Message ID: @.***>

Lenin Torres Head of AI (+593-2) 392-3400

@.***

Av. Orellana E9-195 y Av. 6 de Diciembre, Edif. Alisal de Orellana, Of. 804. Quito - Ecuador

www.actuaria.com En Actuaria, actuamos por un mundo mejor con los ​objetivos de desarrollo sostenible. Términos y condiciones - Seguridad de la información

lenintorresact avatar May 13 '26 17:05 lenintorresact

The reconfigure fix is included in agents-cli 0.2.0, just released. Please reopen if you are still getting crashes!

sushicw avatar May 19 '26 01:05 sushicw