When tryin to get hystorycal data from gui i get this on cm160server console and gui stay searching forever:
Unhandled exception in thread started by <bound method Server.handle_socket of <
Server(Thread-2, started daemon 2940)>>
Traceback (most recent call last):
File "cm160Server.py", line 878, in handle_socket
File "cm160Server.py", line 911, in __handleClientCmd
File "cm160Server.py", line 945, in __getLogData
File "_strptime.pyc", line 325, in _strptime
ValueError: time data '2012-dic-11 00:00:00' does not match format '%Y-%b-%d %H:
%M:%S'
I'll take a look at this and get back to you
PAUL
Hi Paul,
i think it's related with month name "DIC", in italian language.
Perhaps the server waits for an english string (DEC)?
Alex
I think you're right. Could you try running the following on your system and sending back the response ?
python
>>> import locale
>>> locale.setlocale(locale.LC_ALL, '')
On my machine this returns
'en_GB.UTF-8'
as I'm in the UK
If your machine is correctly set-up with the Italian locale then you could try adding the two lines detailed above just above the following line in the cm160servcer.py file.
import serial
Paul
We are right, setting the locale into python server side it works...but...
I've my server into an embedded device where i can't set the locale, so python uses the default 'C' and cannot be changed.
In this case, it would be nice or forcing, via setup, the locale in the client java side, or make the search locale indipendent (ie. using numeric date format).
Alex.
Hi Alex,
Sorry I haven't got back to you earlier, been a bit busy.
The data that caused the exception is from the CM160 device itself, therefore if you can't change the locale in the H/W platform (raspberry PI ?) it's going to cause the exception you sent.
You could hack the python code (some example code shown below) to replace Italian month names with English month names. Not ideal but the best solution is probably to set the correct locale on the python platform.
example code
New method
def _ensureEnglishMonthNames(self, text):
"""Hack !!!. Convert Italian 3 digit month names to English month names."""
if text.find('gen') != -1:
text = text.replace('gen', 'jan')
if text.find('mag') != -1:
text = text.replace('mag', 'may')
if text.find('giu') != -1:
text = text.replace('giu', 'jun')
if text.find('lug') != -1:
text = text.replace('lug', 'jul')
if text.find('ago') != -1:
text = text.replace('ago', 'aug')
if text.find('set') != -1:
text = text.replace('set', 'sep')
if text.find('ott') != -1:
text = text.replace('ott', 'oct')
if text.find('dic') != -1:
text = text.replace('dic', 'dec')
return text
And then at the point the exception occurred
#Attempt to extract the dates and resolution required
if len(elems) == 5:
startTime = datetime.datetime.strptime(self._ensureEnglishMonthNames(elems[1]) , "%Y-%b-%d %H:%M:%S")
stopTime = datetime.datetime.strptime(self._ensureEnglishMonthNames(elems[2]) , "%Y-%b-%d %H:%M:%S")
#This element determines how often we should report the values
#from the log file. It may be
Please note that I have not checked this example.
Paul
View and moderate all "bugs Discussion" comments posted by this user
Mark all as spam, and block user from posting to "Bugs"
I was in the way to fill a bug concerning the ValueError exception, but noticed there was an open thread yet. I'm running the lastest Ubuntu.
To fix the issue, I had to add the following in cm160Server.py at the very start of the program (below the __main__ stuff) :
import locale
locale.setlocale(locale.LC_ALL, '')
That's all!
Thanks for the fix, I'll add it to the next release
Paul