OctoPrint not saving any settings

Since I first started to use OctoPrint (which was just a few months ago) I have the issue that whatever settings I change keep disappearing after I reboot the Pi. With "settings" I am talking about the timelapse settings as well as the g-code scripts. Changes on the printer profile seem to work.

I am using OctoPrint on a Raspberry Pi 3B+ from fresh OctoPi-Installations. Happened at 0.16.0 to 0.17.0. I tried reflashing several times with different versions and tried 2 different SD cards.

I change nothing from the vanilla OctoPi except edit the wpa file for my wifi and setup my printer with the default dialog. I do not use any strange characters in my printer profile name. Even though I change the pi username, I also tried to leave it as default "raspberry". Nothing helps.

I may note: Everything else on the Pi and OctoPrint works fine! I can update it, I can upload files and print, it just looses all normal settings after reboot. Uploaded files, the printer profile and even some test files I create over ssh on the pi stay where they are.

This log is from a complete fresh install, here I tried to save at least 2 times which both did not work.

I include the octoprint.log, if there is any other file you might need, just say so.

octoprint.log (26.6 KB)

I am browsing OcotoPrint using Safari on a Mac but also tried to use Firefox and even Chrome. I am completely clueless on this issue as it looks like there is nothing special in my case so this should affect everyone or no-one? If you have any idea on what might be the issue, feel free to share it.

Have you run it in Safe Mode to see if it can save then? If so then one of your plugins is causing the JavaScript to fail.

Actually I never tried safe mode before to be honest, so I just did. Exactly the same behavior though, settings gone after reboot.

Presumably the POST activity is related to attempting to update the settings.

2019-11-16 10:59:12,152 - octoprint - ERROR - Exception on /api/settings [POST]
Traceback (most recent call last):
  File "/home/pi/oprint/local/lib/python2.7/site-packages/flask/app.py", line 1817, in wsgi_app
    response = self.full_dispatch_request()
  File "/home/pi/oprint/local/lib/python2.7/site-packages/flask/app.py", line 1477, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/home/pi/oprint/local/lib/python2.7/site-packages/flask/app.py", line 1381, in handle_user_exception
    reraise(exc_type, exc_value, tb)
  File "/home/pi/oprint/local/lib/python2.7/site-packages/flask/app.py", line 1475, in full_dispatch_request
    rv = self.dispatch_request()
  File "/home/pi/oprint/local/lib/python2.7/site-packages/flask/app.py", line 1461, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "/home/pi/oprint/local/lib/python2.7/site-packages/octoprint/server/util/flask.py", line 1276, in decorated_view
    return no_firstrun_access(flask_login.login_required(func))(*args, **kwargs)
  File "/home/pi/oprint/local/lib/python2.7/site-packages/octoprint/server/util/flask.py", line 1295, in decorated_view
    return func(*args, **kwargs)
  File "/home/pi/oprint/local/lib/python2.7/site-packages/flask_login.py", line 758, in decorated_view
    return func(*args, **kwargs)
  File "/home/pi/oprint/local/lib/python2.7/site-packages/flask_principal.py", line 199, in _decorated
    rv = f(*args, **kw)
  File "/home/pi/oprint/local/lib/python2.7/site-packages/octoprint/server/api/settings.py", line 307, in setSettings
    response = _saveSettings(data)
  File "/home/pi/oprint/local/lib/python2.7/site-packages/octoprint/server/api/settings.py", line 528, in _saveSettings
    s.saveScript("gcode", name, script.replace("\r\n", "\n").replace("\r", "\n"))
  File "/home/pi/oprint/local/lib/python2.7/site-packages/octoprint/settings.py", line 1798, in saveScript
UnicodeEncodeError: 'ascii' codec can't encode character u'\xa0' in position 11: ordinal not in range(128)

As best as I can interpret this, the gcode update part of the Settings page failed because of a \R seen in the line ending of your pasted-in gcode (guessing) which came from a UNICODE-formatted file. @foosel might want to hear about the steps you used, assuming that my analysis is correct.

I would certainly be interested to see the gcode script in question, exactly as put into OctoPrint (copy paste between ``` here please, not retyped or anything)

Ok I never really distinguished between the gcode script and the webcam. I just cleared my log and produced a fresg log file in which I first tried to save webcam settings, rebooted and then I tried to save my g-code script and rebooted again.

octoprint-new.log (27.7 KB)

The g-code line I paste, I have to admit, is always the same - stored in a "plain-text" .txt document. If I send it to the printer it works though. I know for sure that I copied the line from somewhere before I put in the numbers - which where copied from the OctoPrint Terminal after Calibration.

M301 P28.89 I2.84 D73.35

Maybe... from here:

	def saveScript(self, script_type, name, script):
		script_folder = self.getBaseFolder("scripts")
		filename = os.path.realpath(os.path.join(script_folder, script_type, name))
		if not filename.startswith(os.path.realpath(script_folder)):
			# oops, jail break, that shouldn't happen
			raise ValueError("Invalid script path to save to: {filename} (from {script_type}:{name})".format(**locals()))

		path, _ = os.path.split(filename)
		if not os.path.exists(path):
		encodedScript = script.encode("utf8") # Added OG
		with atomic_write(filename, "wb", max_permissions=0o666) as f:

Okay thanks to your help I managed to get the first problem fixed. Even though I pasted the line of gcode directly to this forum, it did somehow correct the error. However two of the spaces were "non-breaking spaces" (ascii decimal 160 instead of 32).

After I fixed the typo the gcode saved! However the webcam setting still gets lost.

After I fixed the gcode setting I reflashed the sd card - even on a fresh image which has never seen the bad character in a gcode webcam still does not save. I didnt have the time though to investigate which other settings do work or do not work. I will sure keep you updated as soon as I find something new.

A big thank you so far for your help to get the first issue sorted out! :slight_smile:

1 Like