OpenWeatherMap service - JSONException: JSONObject["speed"] not a string

Hi guys,

I am happy to return to MRL after a long absence. I noticed a number of new functions. Well done! and I am happy to try to use them. As the first functionality, I try to use the OpenWeatherMap service and noticed a small problem. In the log there is an exception when processing the response:

python.interpreter.27] ERROR c.m.f.Service [Service.java:2053] python error PyException - null Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "C:/projects/mrl/InMoov/services/H_OpenWeatherMap.py", line 27, in isTheSunShiny
    weather=OpenWeatherMap.fetchForecast(townParam,period)
at org.json.JSONObject.getString(JSONObject.java:721)
at org.myrobotlab.service.OpenWeatherMap.fetchForecast(OpenWeatherMap.java:112)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source).
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
org.json.JSONException: org.json.JSONException: JSONObject["speed"] not a string.
 
I send you "no worky"
GroG's picture

Welcome Back Darek ! It works

Welcome Back Darek !

It works for me when I use a valid key

Darek's picture

GroG, nice to see you

GroG, nice to see you again.
I had the token entered correctly. On the older version (stable) weather service is working well. The problem occurs on the latest version from a few days ago.
GroG's picture

I was testing from

I was testing from develop/head in eclipse .. it seemed to work..

but when i tested from the latest i got the same error you did.

Looking at it i see parsing which appears a bit fragile ...

Fortunately,
the service can also just return raw json ..

Try this

OpenWeatherMap=Runtime.start("OpenWeatherMap", "OpenWeatherMap")
OpenWeatherMap.setApiKey("XXXXXXXXXXXXXXXXXXXXXXXXXX") #https://home.openweathermap.org/
OpenWeatherMap.setUnits("metric") # or imperial
OpenWeatherMap.setLang("fr") # en / de ...
 
# unit is 3 hours steps (1)
# fetch raw data for tomorrow (8) -> because 3*8=24H
# fetch raw data for today (1) -> tomorrow is 1 :
 
r=OpenWeatherMap.fetch("paris,fr",1)
print(r)
 
Darek's picture

hm... When  I have replaced

hm... When  I have replaced the service code with your code. I'm getting an error:

23:10:14.560 [python.interpreter.26] ERROR c.m.f.Service [Service.java:2053] python error PyException - null Traceback (most recent call last):
  File "<string>", line 1, in <module>
NameError: name 'isTheSunShiny' is not defined
 
at org.python.core.Py.NameError(Py.java:290)
at org.python.core.PyFrame.getname(PyFrame.java:257)
at org.python.pycode._pyx261.f$0(<string>:1)
at org.python.pycode._pyx261.call_function(<string>)
at org.python.core.PyTableCode.call(PyTableCode.java:171)
at org.python.core.PyCode.call(PyCode.java:18)
at org.python.core.Py.runCode(Py.java:1614)
at org.python.core.Py.exec(Py.java:1658)
at org.python.util.PythonInterpreter.exec(PythonInterpreter.java:267)
at org.myrobotlab.service.Python$PIThread.run(Python.java:159)
 
 
GroG's picture

I'll need a noworky Darek

I'll need a noworky Darek

Darek's picture

I sent you.

I sent you.

GroG's picture

In the last noWorky I saw

In the last noWorky I saw from you .. I see that its an InMoov script .. 

The latest works with the example I sent.

Might need moz4r to look at this ...

I'll see if a bat signal works ...

moz4r's picture

Hi, it should be fixed in the

Hi, it should be fixed in the last beta build. Some code refactoring will continue, but seem the sun is shiny today.

Darek's picture

 "publishEndSpeaking - about

 "publishEndSpeaking - about the forecast in gdansk, i shall say, it is, clear sky about the temperature, 15 point 4 degrees"  

Now is working fine for my. Thanks a lot.