# Same script fails when run as gateway timer script(nonetype error) but is ok when run in script console

**URL:** <https://forum.inductiveautomation.com/t/same-script-fails-when-run-as-gateway-timer-script-nonetype-error-but-is-ok-when-run-in-script-console/24792>\
**Category:** Ignition\
**Tags:** scripting\
**Created:** [May 8, 2019, 12:58pm UTC](https://forum.inductiveautomation.com/t/same-script-fails-when-run-as-gateway-timer-script-nonetype-error-but-is-ok-when-run-in-script-console/24792 "2019-05-08T12:58:40Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![smenon6](https://avatars.discourse-cdn.com/v4/letter/s/d26b3c/32.png) [@smenon6](https://forum.inductiveautomation.com/u/smenon6)\
**Post date:** [May 8, 2019, 12:58pm UTC](https://forum.inductiveautomation.com/t/same-script-fails-when-run-as-gateway-timer-script-nonetype-error-but-is-ok-when-run-in-script-console/24792/1 "2019-05-08T12:58:40Z")

</div>

Fellow members,

i have ignition 7.9 setup running at my facility, the problem i am facing is that the python script executes without any errors in the script console, but when i run it as a timer based gateway script I get a “Nonetype” error.

The problem occurs at the point where i am trying to subtract two consecutive rows of the dataset inside a for loop. The data in the dataset is a float type, i have tried converting the values to float /int using float()/int() argument, but i still get the same error.

i have also tried initializing two dummy variables as float ( y1 = 10.0 , y2=10.0 ) and later passing the data set values to them, but the result is the same.

Waiting for feedback and suggestions to resolve the issue.

Regards,

Saurabh Menon.

---

<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:** [May 8, 2019, 1:01pm UTC](https://forum.inductiveautomation.com/t/same-script-fails-when-run-as-gateway-timer-script-nonetype-error-but-is-ok-when-run-in-script-console/24792/2 "2019-05-08T13:01:35Z")

</div>

Show your code, and show the full error message from the gateway logs. After you paste into the forum, and lines of just ``` above and below to cause the code/text to be formatted neatly.

---

<div class="post-metadata">

**Author:** ![smenon6](https://avatars.discourse-cdn.com/v4/letter/s/d26b3c/32.png) [@smenon6](https://forum.inductiveautomation.com/u/smenon6)\
**Post date:** [May 9, 2019, 8:36am UTC](https://forum.inductiveautomation.com/t/same-script-fails-when-run-as-gateway-timer-script-nonetype-error-but-is-ok-when-run-in-script-console/24792/3 "2019-05-09T08:36:21Z")

</div>

```auto
# code to generate last 30 days bar graph 
import datetime
now = datetime.datetime.now()
# generate end date string   
edate = str(now.year)+'-'+str(now.month)+'-'+str(now.day)+" 00:00:00"
#the number of days of past data that we need
pastdata = 32 
sdate = str(now.year)+'-'+str((datetime.date.today() - datetime.timedelta(pastdata)).month)+'-'+str((datetime.date.today() - datetime.timedelta(pastdata)).day)+" 00:00:00"

# get tag history data 
data = system.tag.queryTagHistory(paths=['L101 EM/Totalpower'], startDate=sdate, endDate=edate, aggregationMode="LastValue", intervalHours= 24, returnFormat='Wide')
#prepare dataset to calculate daily power consumption 
data1 = system.dataset.deleteRow(data,0)
# create empty dataset
data2 = []
# columnn manes for the bar chart 
header = ["Day","Watts"]

# gather data for daily power consumption calculation 
for i in range (0,data.getRowCount()-1):
	x = str(data1.getValueAt(i,0))[4:10]
	y = data.getValueAt(i+1,1)-data.getValueAt(i,1)
	data2.append([x,y])

system.tag.write('Last30days',system.dataset.toDataSet(header,data2))	

```

# Error code

Traceback (most recent call last):

File “\<TimerScript:Electrical\_Scada/daily\_usage @30,000ms \>”, line 22, in

TypeError: unsupported operand type(s) for -: ‘NoneType’ and ‘NoneType’

7.9.10 (b2018112821)  
Oracle Corporation 1.8.0\_202

---

<div class="post-metadata">

**Author:** ![lrose](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/lrose/32/62724_2.png) [@lrose](https://forum.inductiveautomation.com/u/lrose)\
**Post date:** [May 9, 2019, 11:57am UTC](https://forum.inductiveautomation.com/t/same-script-fails-when-run-as-gateway-timer-script-nonetype-error-but-is-ok-when-run-in-script-console/24792/4 "2019-05-09T11:57:13Z")

</div>

You didn’t show all of your code. The code you posted doesn’t have 21 lines.

Also, as @pturmel mentioned if you place three back ticks like this ``` above and below your code it will cause the code/text to be formatted neatly.

For instance your code you posted above would then look like this:

```auto
import datetime
now = datetime.datetime.now()
#generate end date string
edate = str(now.year)+’-’+str(now.month)+’-’+str(now.day)+" 00:00:00"
#the number of days of past data that we need
pastdata = 32
sdate = str(now.year)+’-’+str((datetime.date.today() - datetime.timedelta(pastdata)).month)+’-’+str((datetime.date.today() - datetime.timedelta(pastdata)).day)+" 00:00:00"

#get tag history data
data = system.tag.queryTagHistory(paths=[‘L101 EM/Totalpower’], startDate=sdate, endDate=edate, aggregationMode=“LastValue”, intervalHours= 24, returnFormat=‘Wide’)

#prepare dataset to calculate daily power consumption
data1 = system.dataset.deleteRow(data,0)
#create empty dataset
data2 = []
#column manes for the bar chart
header = [“Day”,“Watts”]

#gather data for daily power consumption calculation
for i in range (0,data.getRowCount()-1):

```

---

<div class="post-metadata">

**Author:** ![smenon6](https://avatars.discourse-cdn.com/v4/letter/s/d26b3c/32.png) [@smenon6](https://forum.inductiveautomation.com/u/smenon6)\
**Post date:** [May 10, 2019, 2:00am UTC](https://forum.inductiveautomation.com/t/same-script-fails-when-run-as-gateway-timer-script-nonetype-error-but-is-ok-when-run-in-script-console/24792/5 "2019-05-10T02:00:19Z")

</div>

Actually i had deleted the empty lines in code, i have updated the above code. Thanks for pointing the formatting, I missed reading @pturmel turmel comments on formatting.

---

<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:** [May 10, 2019, 2:06am UTC](https://forum.inductiveautomation.com/t/same-script-fails-when-run-as-gateway-timer-script-nonetype-error-but-is-ok-when-run-in-script-console/24792/6 "2019-05-10T02:06:25Z")

</div>

Can you add some print debugging that prints the dataset and run it in each scope?

The error message means your `data.getValueAt` calls are returning `None`.

---

<div class="post-metadata">

**Author:** ![smenon6](https://avatars.discourse-cdn.com/v4/letter/s/d26b3c/32.png) [@smenon6](https://forum.inductiveautomation.com/u/smenon6)\
**Post date:** [May 10, 2019, 7:15am UTC](https://forum.inductiveautomation.com/t/same-script-fails-when-run-as-gateway-timer-script-nonetype-error-but-is-ok-when-run-in-script-console/24792/7 "2019-05-10T07:15:16Z")

</div>

![Capture](https://us1.discourse-cdn.com/inductiveautomation/original/2X/1/177e3c9e91a04c885da67e02d3c6b334fcef282a.png)

@Kevin.Herron

i have added the print statements, and am running the code in the script console. Attached is the screen shot of the data.

---

<div class="post-metadata">

**Author:** ![MMaynard](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/mmaynard/32/3366_2.png) [@MMaynard](https://forum.inductiveautomation.com/u/MMaynard)\
**Post date:** [May 10, 2019, 12:04pm UTC](https://forum.inductiveautomation.com/t/same-script-fails-when-run-as-gateway-timer-script-nonetype-error-but-is-ok-when-run-in-script-console/24792/8 "2019-05-10T12:04:31Z")

</div>

I would say you need to add the tag providers to both the queryTagHistory call and the tag write at the end.  
Gateway scoped scripts do not know what tag providers you are pointing at.

---

<div class="post-metadata">

**Author:** ![smenon6](https://avatars.discourse-cdn.com/v4/letter/s/d26b3c/32.png) [@smenon6](https://forum.inductiveautomation.com/u/smenon6)\
**Post date:** [May 13, 2019, 1:48am UTC](https://forum.inductiveautomation.com/t/same-script-fails-when-run-as-gateway-timer-script-nonetype-error-but-is-ok-when-run-in-script-console/24792/9 "2019-05-13T01:48:18Z")

</div>

@MMaynard : I understand your point. How do I add the providers In the gateway script?

---

<div class="post-metadata">

**Author:** ![jpark](https://avatars.discourse-cdn.com/v4/letter/j/a88e57/32.png) [@jpark](https://forum.inductiveautomation.com/u/jpark)\
**Post date:** [May 13, 2019, 3:19am UTC](https://forum.inductiveautomation.com/t/same-script-fails-when-run-as-gateway-timer-script-nonetype-error-but-is-ok-when-run-in-script-console/24792/10 "2019-05-13T03:19:43Z")

</div>

> [@lrose](#):
>
> paths=[‘L101 EM/Totalpower’]

paths=[‘[default]L101 EM/Totalpower’]
