Gateway script does not write csv

I have a gateway script that has worked all good during several months, but since Monday it is not working properly. I haven’t changed anything in the script or the gateway config.
It is a script that checks data on database, creates rows and copy the data into a csv file. The first part is working, but no the csv file write.
I’ve executed the code on the script console and it works, but not as a gateway script.
Here is the code:

import csv
		if int(,"u")) > 5:
			pass #do nothing
			if int(,"u")) == 1: 
				#do sth
			elif int(,"u")) <=5: 
				#do sth
			*SQL QUERY  - works fine
			if len(pyDataSet) == 0:
				#Create data on database table - works fine
			#Select data for csv file - code works fine
			pyDataSet  = system.db.runQuery(SQL_String, DataBase)
#CSV file does not update
			titles = ['title1','title2','title3']
			with open(pathFile, 'wb') as f:
				writer 	= csv.writer(f, delimiter=';')
		print "Error"

I’ve checked and the unit Y is mapped in ignition server and I have access. On Gateway I see the script runs with no errors. I see the data created on the database table, but the file is not updated.
I have no clue where the problem is, because it was working until this week. Do you have any idea?


If it was working for months prior, I would check IT. More than likely they updated something causing permission issues. i.e. sounds like a write permission issue since everything was working.

Any indicators in the console or wrapper log? You should be able to see some error.


I’d recommend adding a logger to the beginning like

logger = system.util.getLogger("CSV Generator")

and then changing this

		print "Error"

which does not really help you (that print statement you wont be able to see and it it does not give you any information)

to something like

 except java.lang.Throwable, e:
    logger.error("Java error occured")
except Exception, e:
    logger.error("Python error occured")

So that you can see what is going wrong when you check out the server logs.

You will need an import java.lang.Throwable at top as well to use this script.


Total tangent, but I would recommend passing the exception directly to logger.error so that you get the full stacktrace in the logs:

 except java.lang.Throwable, e:
    logger.error("Java error occured", e)

Oh that’s nice. I didn’t realize I could do it like that. Even more succint.

thank you all, you were right, it’s related to permissions to write in the folder. I’ve seen the messages scripting your suggestions.
I’ll need to ask why there isn’t permissions anymore from gateway, because do we have them from clients.

1 Like

By default, Windows services run using a fairly restricted system account. Not at all like a user account. You can change this, but be aware that the default system account also has some admin privileges that user accounts typically do not.

1 Like