Skip to content

Unicode character encoding error when building Flet app in GitHub Actions #5272

Description

@KeimaSenpai

Duplicate Check

Describe the bug

Unicode character encoding error when building Flet app in GitHub Actions

Description

When trying to build a Windows application using flet build windows in GitHub Actions, the process fails with a Unicode encoding error. The specific error occurs when Rich (used by Flet) attempts to display the character \u25cf (a black circle bullet point) in a Windows console that is using codepage CP1252.

Repository with the issue

My repository where the error occurs: https://github.com/KeimaSenpai/XLauncher-ui/

Attempted Fixes

I've tried:

  1. Setting codepage to UTF-8 with chcp 65001
  2. Setting PYTHONIOENCODING=utf-8 environment variable
  3. Using the --no-rich-output flag with flet build windows

None of these solutions have resolved the issue.

Environment

  • OS: Windows (GitHub Actions runner)
  • Python version: 3.12.2
  • Flet version: [latest]
  • Flutter version: 3.24.0

Code sample

My GitHub Actions workflow file

Code
name: Windows Build

on:
  # Allows you to run this workflow manually from the Actions tab of the repository
  workflow_dispatch:

env:
  # https://flet.dev/docs/publish#versioning
  BUILD_NUMBER: 6
  BUILD_VERSION: 1.0.7
  PYTHON_VERSION: 3.12.2
  FLUTTER_VERSION: 3.24.0

jobs:
  build:
    runs-on: windows-latest

    steps:
    - name: Checkout code
      uses: actions/checkout@v4

    - name: Setup Python ${{ env.PYTHON_VERSION }}
      uses: actions/setup-python@v5
      with:
        python-version: ${{ env.PYTHON_VERSION }}

    - name: Install Python Dependencies
      run: |
        python -m pip install --upgrade pip
        pip install -r requirements.txt

    - name: Setup Flutter ${{ env.FLUTTER_VERSION }}
      uses: subosito/flutter-action@v2
      with:
        flutter-version: ${{ env.FLUTTER_VERSION }}

    - name: Flet Build Windows
      run: |
        flutter config --no-analytics
        flet build windows --verbose --no-rich-output --build-number=$env:BUILD_NUMBER --build-version=$env:BUILD_VERSION

    - name: Compress folder
      shell: powershell
      run: |
        Compress-Archive -Path build/windows -DestinationPath build/XLauncher-Windows.zip

    - name: Create GitHub Release
      id: create_release
      uses: actions/create-release@v1
      env:
        GITHUB_TOKEN: ${{ secrets.TOKEN }}
      with:
        tag_name: v${{ env.BUILD_VERSION }}
        release_name: "XLauncher v${{ env.BUILD_VERSION }}"
        body: |
          ## 🚀 Funciones
          - [x] Notificación al ejecutar una version
        draft: false
        prerelease: false

    - name: Upload Build to Release
      uses: actions/upload-release-asset@v1
      env:
        GITHUB_TOKEN: ${{ secrets.TOKEN }}
      with:
        upload_url: ${{ steps.create_release.outputs.upload_url }}
        asset_path: build/XLauncher-Windows.zip  # Path to the zipped file
        asset_name: XLauncher-Windows.zip
        asset_content_type: application/zip

To reproduce

Steps to reproduce

  1. Create a GitHub Actions workflow with a Windows runner
  2. Install Python and Flutter
  3. Try to build a Flet app using flet build windows

Expected behavior

No response

Screenshots / Videos

Captures

[Upload media here]

Operating System

Windows

Operating system details

Windows 10

Flet version

0.27.6

Regression

No, it isn't

Suggestions

Possible Solution

The issue appears to be in how Rich handles Unicode characters when rendering to the Windows console in GitHub Actions environment. A potential fix might be:

  1. Modify Rich to handle Unicode characters better in Windows environments
  2. Add an option to completely disable all special characters in Rich output
  3. Create a wrapper script that captures and filters the output before it's sent to the console

Additional Context

This seems to specifically happen in GitHub Actions environment, as the same command works fine on local Windows machines. The character causing the issue (\u25cf) is a black circle bullet point which Rich is trying to use for formatting its output.

Logs

Logs

Error message

UnicodeEncodeError: 'charmap' codec can't encode character '\u25cf' in position 2: character maps to <undefined>

Full error trace

Traceback (most recent call last):
  File "C:\hostedtoolcache\windows\Python\3.12.2\x64\Lib\site-packages\rich\live.py", line 122, in start
    self.refresh()
  File "C:\hostedtoolcache\windows\Python\3.12.2\x64\Lib\site-packages\rich\live.py", line 241, in refresh
    with self.console:
  File "C:\hostedtoolcache\windows\Python\3.12.2\x64\Lib\site-packages\rich\console.py", line 866, in __exit__
    self._exit_buffer()
  File "C:\hostedtoolcache\windows\Python\3.12.2\x64\Lib\site-packages\rich\console.py", line 824, in _exit_buffer
    self._check_buffer()
  File "C:\hostedtoolcache\windows\Python\3.12.2\x64\Lib\site-packages\rich\console.py", line 2033, in _check_buffer
    self._write_buffer()
  File "C:\hostedtoolcache\windows\Python\3.12.2\x64\Lib\site-packages\rich\console.py", line 2069, in _write_buffer
    legacy_windows_render(buffer, LegacyWindowsTerm(self.file))
  File "C:\hostedtoolcache\windows\Python\3.12.2\x64\Lib\site-packages\rich\_windows_renderer.py", line 17, in legacy_windows_render
    term.write_styled(text, style)
  File "C:\hostedtoolcache\windows\Python\3.12.2\x64\Lib\site-packages\rich\_win32_console.py", line 441, in write_styled
    self.write_text(text)
  File "C:\hostedtoolcache\windows\Python\3.12.2\x64\Lib\site-packages\rich\_win32_console.py", line 402, in write_text
    self.write(text)
  File "C:\hostedtoolcache\windows\Python\3.12.2\x64\Lib\encodings\cp1252.py", line 19, in encode
    return codecs.charmap_encode(input,self.errors,encoding_table)[0]
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
UnicodeEncodeError: 'charmap' codec can't encode character '\u25cf' in position 2: character maps to <undefined>

Additional details

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions