Strange UnicodeEncodeError in Windows image on Azure DevOps and Github

Inada Naoki songofacandy at gmail.com
Fri Nov 11 21:53:42 EST 2022


On Sat, Nov 12, 2022 at 10:21 AM 12Jessicasmith34
<12jessicasmith34 at gmail.com> wrote:
>
>
> Two questions: any idea why this would be happening in this situation? AFAIK, stdout *is* a console when these images are running the python process. Second - is there a way I can check the locale and code page values that you mentioned? I assume I could call GetACP using ctypes, but maybe there is a simpler way?
>

Maybe, python doesn't write to console in this case.

  python -(pipe)-> PowerShell -> Console

In this case, python uses ACP for writing to pipe.
And PowerShell uses OutputEncoding for reading from pipe.

If you want to use UTF-8 on PowerShell in Windows,

 * Set PYTHONUTF8=1 (Python uses UTF-8 for writing into pipe).
 * Set `$OutputEncoding =
[System.Text.Encoding]::GetEncoding('utf-8')` in PowerShell profile.

Regards,

-- 
Inada Naoki  <songofacandy at gmail.com>


More information about the Python-list mailing list