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

settings.setenv Fails With UnicodeDecodeError #770

Closed
OmmarShaikh01 opened this issue Jul 20, 2022 · 1 comment
Closed

settings.setenv Fails With UnicodeDecodeError #770

OmmarShaikh01 opened this issue Jul 20, 2022 · 1 comment
Labels

Comments

@OmmarShaikh01
Copy link

Code Repository Apollo

Describe the bug
Running an executable built by pyinstaller dynaconf raises UnicodeDecodeError

Dynaconf Initlization

settings = Dynaconf(
    load_dotenv=False,
    project_root=os.path.dirname(ROOT),
    settings_files=[
        os.path.join(ROOT, "default_settings.toml"),
        os.path.join(ROOT, "default_testing_settings.toml"),
        os.path.join(ROOT, "default_qt_testing_settings.toml"),
        os.path.join(ROOT, "settings.toml"),
        os.path.join(ROOT, "testing_settings.toml"),
        os.path.join(ROOT, "qt_testing_settings.toml"),
    ],
    envvar_prefix="DYNACONF",
    environments=True,
    env_switcher="ENV_FOR_DYNACONF",
    validate_only_current_env=True,
    dynaconf_skip_loaders=False,
    validators=validate(),
)

Error Traceback

Traceback (most recent call last):
  File "apollo\__main__.py", line 18, in <module>
    settings.setenv("PRODUCTION")
  File "D:\Dev\Apollo\dist\Apollo-0.1.0\.venv\lib\site-packages\dynaconf\base.py", line 113, in __getattr__
    self._setup()
  File "D:\Dev\Apollo\dist\Apollo-0.1.0\.venv\lib\site-packages\dynaconf\base.py", line 172, in _setup
    self._wrapped = Settings(
  File "D:\Dev\Apollo\dist\Apollo-0.1.0\.venv\lib\site-packages\dynaconf\base.py", line 251, in __init__
    self.execute_loaders()
  File "D:\Dev\Apollo\dist\Apollo-0.1.0\.venv\lib\site-packages\dynaconf\base.py", line 1035, in execute_loaders
    execute_hooks("post", self, env, silent=silent, key=key)
  File "D:\Dev\Apollo\dist\Apollo-0.1.0\.venv\lib\site-packages\dynaconf\loaders\__init__.py", line 121, in execute_hooks
    hook_module = py_loader.import_from_filename(
  File "D:\Dev\Apollo\dist\Apollo-0.1.0\.venv\lib\site-packages\dynaconf\loaders\py_loader.py", line 90, in import_from_filename
    if filename in [item.filename for item in inspect.stack()]:
  File "D:\Programs\Python39\lib\inspect.py", line 1554, in stack
    return getouterframes(sys._getframe(1), context)
  File "D:\Programs\Python39\lib\inspect.py", line 1531, in getouterframes
    frameinfo = (frame,) + getframeinfo(frame, context)
  File "D:\Programs\Python39\lib\inspect.py", line 1505, in getframeinfo
    lines, lnum = findsource(frame)
  File "D:\Programs\Python39\lib\inspect.py", line 833, in findsource
    lines = linecache.getlines(file)
  File "linecache.py", line 46, in getlines
  File "linecache.py", line 137, in updatecache
  File "codecs.py", line 322, in decode
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xe5 in position 9: invalid continuation byte

To Reproduce
Steps to reproduce the behavior:

  1. Install poetry to manage the environment
  2. Build the application package using .\tools\build.ps1 -format frozen-zip
  3. execute Apollo.exe generated in .\dist\build\Apollo

Expected behavior
Apollo.exe Should Launch the mainwindow.

Environment (please complete the following information):

  • OS: Windows/10
  • Dynaconf Version ^3.1.8
  • Frameworks in use Qt
@OmmarShaikh01
Copy link
Author

Pyinstaller Compiles the Dynaconf Modules and loaders so when dynaconf.loader.py_loader tries to load files from the inspect stack trace it tries to read compiled pyc files and fails on UnicodeDecodeError. The fix is to pacakage dynaconf and python-dotenv[cli] as a package without compiling it by using the --collect-all argument of pyinstaller

@OmmarShaikh01 OmmarShaikh01 changed the title [bug] settings.setenv Fails With UnicodeDecodeError settings.setenv Fails With UnicodeDecodeError Jul 24, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant