Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UnicodeDecodeError when executing flet build on Windows (ja) #2448

Closed
mochimochiki opened this issue Jan 21, 2024 · 1 comment · Fixed by #2482
Closed

UnicodeDecodeError when executing flet build on Windows (ja) #2448

mochimochiki opened this issue Jan 21, 2024 · 1 comment · Fixed by #2482
Assignees
Labels
bug Something isn't working

Comments

@mochimochiki
Copy link

Description

When executing flet build on Windows with the system locale ja, a UnicodeDecodeError related to the 'cp932' codec occurs. Referring to yaml/pyyaml/issues/123, opening a yaml file using open() without specifying an encoding can cause this problem in some locales. Specifying open( ...coding='utf-8') may resolve the issue.

Code example to reproduce the issue:

import flet as ft

def main(page: ft.Page):
    # add/update controls on Page
    pass

ft.app(target=main)

Describe the results you received:

When running flet build windows or other target, the following error occurs:

Traceback (most recent call last):
  File "<frozen runpy>", line 198, in _run_module_as_main
  File "<frozen runpy>", line 88, in _run_code
  File "C:\flet_test\.venv\Scripts\flet.exe\__main__.py", line 7, in <module>
  File "C:\flet_test\.venv\Lib\site-packages\flet\cli\cli.py", line 83, in main
    args.handler(args)
  File "C:\flet_test\.venv\Lib\site-packages\flet\cli\commands\build.py", line 353, in handle
    pubspec = yaml.safe_load(f)
              ^^^^^^^^^^^^^^^^^
  ...
UnicodeDecodeError: 'cp932' codec can't decode byte 0x97 in position 3003: illegal multibyte sequence

Describe the results you expected:

The build process should complete successfully without encountering UnicodeDecodeError.

Workaround

I was able to successfully build by setting Set PYTHONUTF8=1 before building.

Additional information you deem important (e.g. issue happens only occasionally):

OS system locale is 'ja'.

python
> import locale
> locale.getpreferredencoding()
'cp932'

Flet version (pip show flet):

0.19.0

Operating system:

Windows 11 Pro

Additional environment details:

  • System locale: ja
  • Python version: 3.12.1
@FeodorFitsner
Copy link
Contributor

I guess we should specify encoding in all open() methods, both reads and writes, to make it right?

@FeodorFitsner FeodorFitsner added the bug Something isn't working label Jan 21, 2024
@FeodorFitsner FeodorFitsner self-assigned this Jan 21, 2024
@FeodorFitsner FeodorFitsner moved this to 👀 In review in Flet Development Jan 21, 2024
@FeodorFitsner FeodorFitsner moved this from 👀 In review to 🏗 In progress in Flet Development Jan 21, 2024
@FeodorFitsner FeodorFitsner moved this from 🏗 In progress to ✅ Done in Flet Development Jan 23, 2024
FeodorFitsner added a commit that referenced this issue Jan 24, 2024
@ndonkoHenri ndonkoHenri linked a pull request Jan 26, 2024 that will close this issue
zrr1999 pushed a commit to zrr1999/flet that referenced this issue Jul 17, 2024
* Basic imports/exports

* Moved models and protocols to their respective controls

* Fix tests

* Exports cleanup

* Flet custom controls example with demo app

* Working example for mycontrol

* typeName > controlType renamed

* src_pubspec_path

* Inject Flutter dependencies to a template

* Copy both dependencies and dependency_overrides

* Fixed: `flet build` with `A package may not list itself as a dependency.` error occurs

Fix flet-dev#2305

* All file operations with UTF-8 encoding

Fix flet-dev#2448

* flet build -vv (maximum verbose) should yield verbose output from underlying flutter build command

Close flet-dev#2454

* Pin `flet build` template to Flet version

Close flet-dev#2459

* Do not use StoreConnector for dispatch

* Get rid of StoreConnector wherever we can

* updateControlProps, sendControlEvent

* Make `page.platform` writable to test adaptive controls

Close flet-dev#2470

* Get rid of dispatch across the code

* sendControlEvent is used everywhere

* Switch to mixins

* Renamed mixins

* Fix Pagelet control

* FletStoreMixin added

* Working with methods
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

2 participants