Odd locale error that has disappeared on reboot.
Chris Green
cl at isbd.net
Wed Dec 8 04:50:32 EST 2021
Julio Di Egidio <julio at diegidio.name> wrote:
> On 07/12/2021 16:28, Chris Green wrote:
> > I have a very short Python program that runs on one of my Raspberry
> > Pis to collect temperatures from a 1-wire sensor and write them to a
> > database:-
> >
> > #!/usr/bin/python3
> > #
> > #
> > # read temperature from 1-wire sensor and store in database with date and time
> > #
> > import sqlite3
> > import time
> >
> > ftxt = str(open("/sys/bus/w1/devices/28-01204e1e64c3/w1_slave").read(100))
> > temp = (float(ftxt[ftxt.find("t=") +2:]))/1000
> > #
> > #
> > # insert date, time and temperature into the database
> > #
> > tdb = sqlite3.connect("/home/chris/.cfg/share/temperature/temperature.db")
> > cr = tdb.cursor()
> > dt = time.strftime("%Y-%m-%d %H:%M")
> > cr.execute("Insert INTO temperatures (DateTime, Temperature) VALUES(?,
> round(?, 2))", (dt, temp)
> > )
> > tdb.commit()
> > tdb.close()
> >
> > It's run by cron every 10 minutes.
> >
> >
> > At 03:40 last night it suddenly started throwing the following error every
> > time it ran:-
> >
> > Fatal Python error: initfsencoding: Unable to get the locale encoding
> > LookupError: unknown encoding: UTF-8
> >
> > Current thread 0xb6f8db40 (most recent call first):
> > Aborted
> >
> > Running the program from the command line produced the same error.
> > Restarting the Pi system has fixed the problem.
> >
> >
> > What could have caused this? I certainly wasn't around at 03:40! :-)
> > There aren't any automatic updates enabled on the system, the only
> > thing that might have been going on was a backup as that Pi is also
> > my 'NAS' with a big USB drive connected to it. The backups have been
> > running without problems for more than a year. Looking at the system
> > logs shows that a backup was started at 03:35 so I suppose that *could*
> > have provoked something but I fail to understand how.
>
> Since it's a one-off, doesn't sound like a system problem. The easiest
> might be that you try-catch that call and retry when needed, and I'd
> also check that 'ftxt' is what it should be: "external devices" may
> fail, including when they do produce output...
>
Well it repeated every ten minutes through the night until I rebooted
the system, so it wasn't really a "one off". I hasn't repeated since
though.
--
Chris Green
·
More information about the Python-list
mailing list