sunfounder / nas-kit

SunFounder NAS Kit for Raspberry Pi
15 stars 16 forks source link

Error when locale does use a special character for the decimal #6

Open ghost opened 4 years ago

ghost commented 4 years ago

After setting up the locale to fr_FR.UTF-8 using raspi-configand launching the script, I get the following error :

pi@raspberrypi:~nas-kit $ python3 main/raspi_omv_main.py
Exception in thread Thread-1
Traceback (most recent call last):
  File "/usr/lib/python3.7/threading.py", line 917, in _boostrap_inner
    self.run()
  File "/usr/lib/python3.7/threading.py", line 865, in run
    self._target(*self._args, **self._kwargs)
  File "main/raspi_omv_main.py", line 312, in main
    page(current_page)
  File "/home/pi/nas-kit/main/page.py", line 76, in __call__
    eval(cmd)
  File "<string>", line 1, in <module>
  File "/home/pi/nas-kit/main/page.py", line 99, in page_1_update
    pi_msg = pi_read()
  File "/home/pi/nas-kit/main/page.py", line 150, in pi_read
    "cpu_usage": cpu_usage(),
  File "/home/pi/nas-kit/main/page.py", line 106, in cpu_usage
    result = round(100 - float(result), 2)
ValueError: could not convert string to float: '80,35'

The problem seems to come fram the fact that the french locale use , as a decimal separator, and not .. The workaround is to revert back to en_US.UTF-8 locale, but it should be possible to handle this problem using the locale library.

nostromo1st commented 4 years ago

Hello Blablux,

I have the same problem. Have you resolved it or not ?

ghost commented 4 years ago

@nostromo1st I'm still using the en_US.UTF-8 locale. I had no time yet to look into the code...