Could not initialize settings manager: source code string cannot contain null bytes

What is the problem?

OctoPrint does not start.

Would love to have it working and back to printing without starting from scratch (new installation and all changes gone etc.)

What did you already try to solve it?

  • Tried to restart Raspberry multiple times
  • Checked if the OctoPrint is running ps -ef | grep -i octoprint | grep -i python, it was not.
  • Checked the log ~/.octoprint/logs/octoprint.log and the last lines are from 2022-08-08
  • Tried the steps provided in: OctoPrint do not start anymore - #4 by foosel
    • When trying to start it I get the following error:
pi@piocto:~ $ source ~/oprint/bin/activate
(oprint) pi@piocto:~ $ octoprint serve --debug --host 127.0.0.1
2022-08-15 11:41:57,470 - octoprint.startup - CRITICAL - Could not initialize settings manager: source code string cannot contain null bytes
2022-08-15 11:41:57,471 - octoprint.startup - CRITICAL - There was a fatal error starting up OctoPrint.
Could not initialize settings manager: source code string cannot contain null bytes
There was a fatal error starting up OctoPrint.
  • And same in safe mode:
(oprint) pi@piocto:~ $ octoprint serve --safe --debug --host 127.0.0.1
2022-08-15 12:22:27,942 - octoprint.startup - CRITICAL - Could not initialize settings manager: source code string cannot contain null bytes
2022-08-15 12:22:27,943 - octoprint.startup - CRITICAL - There was a fatal error starting up OctoPrint.
Could not initialize settings manager: source code string cannot contain null bytes
There was a fatal error starting up OctoPrint.

Have you tried running in safe mode?

Yes, same error when tried to start

Did running in safe mode solve the problem?

No

Systeminfo Bundle

Not able to start OctoPrint so don't able to provide this info from the UI.
And from the command line:

(oprint) pi@piocto:~ $ octoprint systeminfo
Could not initialize settings manager: source code string cannot contain null bytes
There was a fatal error initializing the platform.

Additional information about your setup

OctoPrint version, OctoPi version, printer, firmware, browser, operating system, ... as much data as possible

OctoPrint version : 1.8.1
OctoPi version : 0.18.0
Operating system: OctoPi

Printer: Ender 3 Pro
Firmware: Marlin 2.0.9.3
Browser(s): Firefox 103.0.2

Space of the Raspberry (I have 32GB card):

(oprint) pi@piocto:~ $ df -H
Filesystem      Size  Used Avail Use% Mounted on
/dev/root        31G  2.4G   27G   9% /
devtmpfs        423M     0  423M   0% /dev
tmpfs           458M     0  458M   0% /dev/shm
tmpfs           458M   18M  440M   4% /run
tmpfs           5.3M  4.1k  5.3M   1% /run/lock
tmpfs           458M     0  458M   0% /sys/fs/cgroup
/dev/mmcblk0p1  265M   51M  214M  20% /boot
tmpfs            92M     0   92M   0% /run/user/1000

Last time working: 2022-08-08 when there was a power cut. Was not printing anything at that time.

Sounds like your installation is corrupt and the whole settings manager is gone. Try

Thanks for the reply!

I now tried to reinstall OctoPrint and here are the results:

pi@piocto:~ $ ~/oprint/bin/pip install --force-reinstall OctoPrint==1.8.1 --no-cache-dir
Traceback (most recent call last):
  File "/home/pi/oprint/bin/pip", line 10, in <module>
    sys.exit(main())
  File "/home/pi/oprint/lib/python3.7/site-packages/pip/_internal/cli/main.py", line 73, in main
    command = create_command(cmd_name, isolated=("--isolated" in cmd_args))
  File "/home/pi/oprint/lib/python3.7/site-packages/pip/_internal/commands/__init__.py", line 105, in create_command
    module = importlib.import_module(module_path)
  File "/home/pi/oprint/lib/python3.7/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
  File "<frozen importlib._bootstrap>", line 983, in _find_and_load
  File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 728, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "/home/pi/oprint/lib/python3.7/site-packages/pip/_internal/commands/install.py", line 17, in <module>
    from pip._internal.cli.req_command import RequirementCommand, with_cleanup
  File "/home/pi/oprint/lib/python3.7/site-packages/pip/_internal/cli/req_command.py", line 18, in <module>
    from pip._internal.index.collector import LinkCollector
  File "/home/pi/oprint/lib/python3.7/site-packages/pip/_internal/index/collector.py", line 14, in <module>
    from pip._vendor import html5lib, requests
  File "/home/pi/oprint/lib/python3.7/site-packages/pip/_vendor/requests/__init__.py", line 128, in <module>
    from .api import request, get, head, post, patch, put, delete, options
  File "/home/pi/oprint/lib/python3.7/site-packages/pip/_vendor/requests/api.py", line 13, in <module>
    from . import sessions
  File "/home/pi/oprint/lib/python3.7/site-packages/pip/_vendor/requests/sessions.py", line 28, in <module>
    from .adapters import HTTPAdapter
  File "/home/pi/oprint/lib/python3.7/site-packages/pip/_vendor/requests/adapters.py", line 44, in <module>
    from pip._vendor.urllib3.contrib.socks import SOCKSProxyManager
  File "/home/pi/oprint/lib/python3.7/site-packages/pip/_vendor/urllib3/contrib/socks.py", line 44, in <module>
    import socks
ValueError: source code string cannot contain null bytes

Some Python problem or is my whole memory card probably corrupted?

Either the virtual env is broken, or the whole card is giving up. Frankly, at this point in your shoes I'd start fresh. If you have a recent backup, that makes things easier, otherwise you might be able to transfer the settings and files and such over manually, but that's going to be fiddly.

Just for the record (and I'm not saying this is the reason here), but always shut down your Pi first via the shutdown menu in OctoPrint's navbar, never just power it off without having it run through shutdown first as that can also lead to file system corruption.

1 Like

I highly recommend a USB to SD card adapter. I use one on my RPi to clone the OS using rpi-clone.

1 Like

Okay, will start fresh. Thanks for the explanation.

I do not have any backup, but will try to remember make them in the future if this happens again.
UPS might be little overkill to prevent the issue in case of future power cuts but maybe, maybe :slight_smile:

Thanks for the tip! Will look that also.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.