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

AttributeError: 'NoneType' object has no attribute 'encoding' #106

Open
cedricscheepers opened this issue Oct 26, 2023 · 1 comment
Open

Comments

@cedricscheepers
Copy link

cedricscheepers commented Oct 26, 2023

Hi

I trust you can help me. I am successfully extracting MT940 from a text file, on Mac and Windows. When I then use PyInstaller to create an exe (on Windows), I get the following error (but not in my IDE) and traceback:

File "modules\gui.py", line 550, in __on_timer
  File "modules\playbot.py", line 284, in run
  File "modules\playbot.py", line 1984, in _run_process
  File "modules\playbot.py", line 2035, in __call_function
  File "modules\playbot.py", line 1037, in _extract_mt940
  File "modules\files.py", line 454, in file_open_mt940
  File "<frozen importlib._bootstrap>", line 1176, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1147, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 690, in _load_unlocked
  File "PyInstaller\loader\pyimod02_importers.py", line 391, in exec_module
  File "mt940\__init__.py", line 3, in <module>
  File "<frozen importlib._bootstrap>", line 1176, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1147, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 690, in _load_unlocked
  File "PyInstaller\loader\pyimod02_importers.py", line 391, in exec_module
  File "mt940\json.py", line 7, in <module>
  File "<frozen importlib._bootstrap>", line 1176, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1147, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 690, in _load_unlocked
  File "PyInstaller\loader\pyimod02_importers.py", line 391, in exec_module
  File "mt940\models.py", line 13, in <module>
  File "<frozen importlib._bootstrap>", line 1176, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1147, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 690, in _load_unlocked
  File "PyInstaller\loader\pyimod02_importers.py", line 391, in exec_module
  File "mt940\_compat.py", line 117, in <module>
AttributeError: 'NoneType' object has no attribute 'encoding'

As I've mentioned, this works when my app is not an executable, but fails when it is.

In case it helps, here is my code where I catch this exception:

    try:
        transactions = mt940.parse(path)

        return loads(dumps(transactions, cls=mt940.JSONEncoder))
    except Exception as err:
        return err

I look forward to hearing from you.

Kind regards
Cedric

@wolph
Copy link
Owner

wolph commented Oct 27, 2023

The library currently expects sys.stdout to be available in some form or another. In your cases it appears to be None. You could monkeypatch it from your code like this:

import io
import sys


if sys.stdout is None:
    sys.stdout = io.StringIO()

if sys.stderr is None:
    sys.stderr = io.StringIO()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants