I am running the following script. It is not executing and gets this error every time. However, when I run the thing in the script console it works. Any ideas?
Script
import time
system.util.getLogger('CurrentWeather').info("Executing gateway script CurrentWeather...")
api_key = "<OMITTED>"
city_id = <OMITTED>
url = "https://api.openweathermap.org/data/2.5/weather?id=%s&units=imperial&appid=%s" % (city_id, api_key)
# gets the url response
response = system.net.httpGet(url)
response_object = system.util.jsonDecode(response)
# gets the temperature
temp = response_object["main"]["temp"]
humidity = response_object["main"]["humidity"]
pressure = response_object["main"]["pressure"]
temp_min = response_object["main"]["temp_min"]
temp_max = response_object["main"]["temp_max"]
visibility = response_object["visibility"]
wind_speed = response_object["wind"]["speed"]
wind_degree = response_object["wind"]["deg"]
sunrise_utc_timestamp = response_object["sys"]["sunrise"]
sunset_utc_timestamp = response_object["sys"]["sunset"]
sunrise = project.Utilities.convert_timestamp(sunrise_utc_timestamp)
sunset = project.Utilities.convert_timestamp(sunset_utc_timestamp)
#print("temp = %s, humidity = %s" % (temp, humidity))
# save the values into the memory tag
w = system.tag.write("CurrentWeather/Updated", system.date.now())
w1 = system.tag.write("CurrentWeather/Temperature", temp)
w2 = system.tag.write("CurrentWeather/Humidity", humidity)
w3 = system.tag.write("CurrentWeather/Pressure", pressure)
w4 = system.tag.write("CurrentWeather/TempMin", temp_min)
w5 = system.tag.write("CurrentWeather/TempMax", temp_max)
w6 = system.tag.write("CurrentWeather/Visibility", visibility)
w7 = system.tag.write("CurrentWeather/WindSpeed", wind_speed)
w8 = system.tag.write("CurrentWeather/WindDegree", wind_degree)
w9 = system.tag.write("CurrentWeather/Sunrise", sunrise)
w10 = system.tag.write("CurrentWeather/Sunset", sunset)
system.util.getLogger('CurrentWeather').info("CurrentWeather...done.")
Here is the error that I get - Line 25 is the httpGet call:
com.inductiveautomation.ignition.common.script.JythonExecException: Traceback (most recent call last): File "", line 25, in IOError: Connection reset
at org.python.core.Py.fromIOException(Py.java:215)
at org.python.core.Py.IOError(Py.java:178)
at com.inductiveautomation.ignition.common.script.builtin.AbstractNetUtilities.httpGet(AbstractNetUtilities.java:256)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.python.core.PyReflectedFunction.__call__(PyReflectedFunction.java:186)
at com.inductiveautomation.ignition.common.script.ScriptManager$ReflectedInstanceFunction.__call__(ScriptManager.java:431)
at org.python.core.PyObject.__call__(PyObject.java:387)
at org.python.core.PyObject.__call__(PyObject.java:391)
at org.python.pycode._pyx2.f$0(:57)
at org.python.pycode._pyx2.call_function()
at org.python.core.PyTableCode.call(PyTableCode.java:165)
at org.python.core.PyCode.call(PyCode.java:18)
at org.python.core.Py.runCode(Py.java:1275)
at com.inductiveautomation.ignition.common.script.ScriptManager.runCode(ScriptManager.java:636)
at com.inductiveautomation.ignition.common.script.ScriptManager.runCode(ScriptManager.java:603)
at com.inductiveautomation.ignition.common.script.TimerScriptTask.run(TimerScriptTask.java:88)
at java.util.TimerThread.mainLoop(Timer.java:555)
at java.util.TimerThread.run(Timer.java:505)
Caused by: org.python.core.PyException: Traceback (most recent call last): File "", line 25, in IOError: Connection reset
... 21 common frames omitted