# Gateway event script

**URL:** <https://forum.inductiveautomation.com/t/gateway-event-script/20878>\
**Category:** Ignition\
**Created:** [November 15, 2018, 7:35am UTC](https://forum.inductiveautomation.com/t/gateway-event-script/20878 "2018-11-15T07:35:22Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![eduardo.ojalvo](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/eduardo.ojalvo/32/14356_2.png) [@eduardo.ojalvo](https://forum.inductiveautomation.com/u/eduardo.ojalvo)\
**Post date:** [November 15, 2018, 7:35am UTC](https://forum.inductiveautomation.com/t/gateway-event-script/20878/1 "2018-11-15T07:35:23Z")

</div>

Hello everybody,

I `ve the next code in a Gateway event script with a timer with 30 seconds :  
It´s about reading data from a JSON file from a “aemet web service” to have the temperatura and humidity.

try:  
source = system.net.httpGet(“[https://opendata.aemet.es/opendata/api/observacion/convencional/datos/estacion/3195/?api\_key=eyJhbKLjKwPK\_fjRd1vHNFGB\_aivzgWE](https://opendata.aemet.es/opendata/api/observacion/convencional/datos/estacion/3195/?api_key=eyJhbKLjKwPK_fjRd1vHNFGB_aivzgWE)”)  
url=system.util.jsonDecode(source)

```
url= (url["datos"])
#a=0
datos=source = system.net.httpGet(url)
lista=system.util.jsonDecode(datos)
#for a in lista:
#	a+=1
#	print(a,valor)
#	temp=lista[(a)]['ta']
#	humed=lista[(a)]['hr']
temp=lista[22]['ta']
humed=lista[22]['hr']

t1=float(temp)
h1=float(humed)

print(t1,h1)
ruta=["Temp","Humedad"]
valores=[t1,h1]
system.tag.writeAll(ruta,valores)

```

except:  
faults\_counter=system.tag.read(“faults”).value  
faults\_counter+=1  
system.tag.write(“faults”,faults\_counter)

When i execute it in a button it works succesfully, but when i try to run it in the Gateway event script timer it doesn´t work.  
My ignition plattfor is a 7.7.8.  
Do you have any idea? Thank you very much.  
Kind regards.

---

<div class="post-metadata">

**Author:** ![c.bertulli](https://avatars.discourse-cdn.com/v4/letter/c/f19dbf/32.png) [@c.bertulli](https://forum.inductiveautomation.com/u/c.bertulli)\
**Post date:** [November 15, 2018, 9:41am UTC](https://forum.inductiveautomation.com/t/gateway-event-script/20878/2 "2018-11-15T09:41:09Z")

</div>

Did you check what the RunTime console is logging? Maybe there is an error, unfortunately when you put script inside the Gateway/Client Events Scripts, in case of error there will be no popup error ( like the one that appears if there is an error in a script inside a button )

---

<div class="post-metadata">

**Author:** ![eduardo.ojalvo](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/eduardo.ojalvo/32/14356_2.png) [@eduardo.ojalvo](https://forum.inductiveautomation.com/u/eduardo.ojalvo)\
**Post date:** [November 15, 2018, 12:49pm UTC](https://forum.inductiveautomation.com/t/gateway-event-script/20878/3 "2018-11-15T12:49:25Z")

</div>

Thank you very much for atention.

I dont´t know whta the error means, do you?  
I attach the error file.

I[error.txt](https://us1.discourse-cdn.com/inductiveautomation/original/2X/6/6a07b98339aa32dd4bc076770f49d2e0bd5b4aa7.txt) (2.3 KB)

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [November 15, 2018, 1:44pm UTC](https://forum.inductiveautomation.com/t/gateway-event-script/20878/4 "2018-11-15T13:44:02Z")

</div>

Here’s your problem:

```auto
File "<TimerScript:OFICINAS_ENGIE_MADRID/Temp_aemet @30,000ms >", line 3, in <module>t ÆIOError: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target

```

There’s likely something wrong with the target website’s HTTPS certificate. Also, you should edit your original post to omit your API key.

---

<div class="post-metadata">

**Author:** ![Sanderd17](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/sanderd17/32/8735_2.png) [@Sanderd17](https://forum.inductiveautomation.com/u/Sanderd17)\
**Post date:** [November 15, 2018, 1:46pm UTC](https://forum.inductiveautomation.com/t/gateway-event-script/20878/5 "2018-11-15T13:46:15Z")

</div>

Hi Eduardo,

Phil is probably correct, I just want to note that the `httpGet` function also has a `bypassCertValidation` option, where you can bypass certificate validation.

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [November 15, 2018, 1:59pm UTC](https://forum.inductiveautomation.com/t/gateway-event-script/20878/6 "2018-11-15T13:59:41Z")

</div>

Yeah, it seems the root CA for that site’s certificate is not trusted by default (not in the Java or Safari CA store, anyway).

You’ll have to manually add it to the Java CA store or, preferably, use the `bypassCertValidation` parameter.

---

<div class="post-metadata">

**Author:** ![eduardo.ojalvo](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/eduardo.ojalvo/32/14356_2.png) [@eduardo.ojalvo](https://forum.inductiveautomation.com/u/eduardo.ojalvo)\
**Post date:** [November 15, 2018, 3:34pm UTC](https://forum.inductiveautomation.com/t/gateway-event-script/20878/7 "2018-11-15T15:34:53Z")

</div>

Hi Kevin,

I have made that change but it´s not working yet, here you are.  
Pls look my attached file about the new error.[new error.txt](https://us1.discourse-cdn.com/inductiveautomation/original/2X/a/a95b1fa0fd98efcda04c46be7a81eaa746f27964.txt) (2.2 KB)

```auto
import system
#import re
try:
	strurl="https://opendata.aemet.es/opendata/api/observacion/convencional/datos/estacion/3195/?api_key=eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJlZHVhcmRvLm9qYWx2b0BlbmdpZS5jb20iLCJqdGkiOiI4ODUxMzM4NS0yZGM3LTRmNjMtOGI2ZC1iM2ZhM2Y3YTU2ZTgiLCJpc3MiOiJBRU1FVCIsImlhdCI6MTU0MTY3NTE3MSwidXNlcklkIjoiODg1MTMzODUtMmRjNy00ZjYzLThiNmQtYjNmYTNmN2E1NmU4Iiwicm9sZSI6IiJ9.Oqo0jtNRwslzq_LqKLjKwPK_fjRd1vHNFGB_aivzgWE"
	source=system.net.httpGet(strurl,bypassCertValidation=0)
	url= (url["datos"])
	#a=0
	datos=source = system.net.httpGet(url)
	lista=system.util.jsonDecode(datos)
	print len(lista)
	#for a in lista:
	#	a+=1
	#	print(a,valor)
	#	temp=lista[(a)]['ta']
	#	humed=lista[(a)]['hr']
	temp=lista[22]['ta']
	humed=lista[22]['hr']
	
	t1=float(temp)
	h1=float(humed)
	
	print(t1,h1)
	ruta=["Temp_ext_wunderground","Humedad_ext_wunderground"]
	valores=[t1,h1]
	system.tag.writeAll(ruta,valores)
except:
	a=system.tag.read("Eventos").value
	a+=1
	system.tag.write("Eventos",a)

```

Thank you very much.

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [November 15, 2018, 3:36pm UTC](https://forum.inductiveautomation.com/t/gateway-event-script/20878/8 "2018-11-15T15:36:11Z")

</div>

> [@eduardo.ojalvo](#):
>
> `bypassCertValidation=0`

You're setting `bypassCertValidation` false - meaning that it will _not_ bypass certificate validation. Send 1 or `True` instead.

---

<div class="post-metadata">

**Author:** ![eduardo.ojalvo](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/eduardo.ojalvo/32/14356_2.png) [@eduardo.ojalvo](https://forum.inductiveautomation.com/u/eduardo.ojalvo)\
**Post date:** [November 15, 2018, 3:47pm UTC](https://forum.inductiveautomation.com/t/gateway-event-script/20878/9 "2018-11-15T15:47:20Z")

</div>

Hi PGriffith,

Yes, you were right.

Now it´s working succesfully.

Thank you very much to all.  
😆
