Script working in console but not on component events

Hey,

I am writing one script to open network drive folder on the button action performed.
I have done all the Mapping required to fetch the drive and script is working in script console but the same is not working either on component event or in gateway script. below is the script attached

import os, fnmatch
path = “\\gnpunnas\Temporary\”
files = fnmatch.filter(os.listdir(path), “*.pdf”)
print files

In perspective, all scripts run on the gateway.

The most likely reason is that your gateway does not have permissions to read the directory.

EDIT: That would be the username the gateway service runs under.

I have changed the log on properties in services section to change as this account but still it didnt work. is there any specific thing i need to do after that.

Is there an error that is thrown?

INFO | jvm 1 | 2022/03/02 11:42:00 | 1
INFO | jvm 1 | 2022/03/02 11:42:00 | 0
INFO | jvm 1 | 2022/03/02 11:42:00 | [default]read
DEBUG | wrapperp | 2022/03/02 11:42:01 | Send a packet PING : ping 00029969
INFO | jvm 1 | 2022/03/02 11:42:01 | WrapperManager Debug: Received a packet PING : ping 00029969
INFO | jvm 1 | 2022/03/02 11:42:01 | WrapperManager Debug: Send a packet PING : ping 00029969
INFO | jvm 1 | 2022/03/02 11:42:01 | E [TagChangeScriptExecutor ] [11:42:01]: Error executing tag change script: perspective_test/New Script
INFO | jvm 1 | 2022/03/02 11:42:01 | com.inductiveautomation.ignition.common.script.JythonExecException: Traceback (most recent call last):
INFO | jvm 1 | 2022/03/02 11:42:01 | File “<TagChangeScript:perspective_test/New Script>”, line 8, in
INFO | jvm 1 | 2022/03/02 11:42:01 | OSError: (20, ‘Not a directory’, ‘\\gnpunnas1b\Temporary\’)

This is the error i found on wrapper.log file in c drive.

  • Did you restart the service after changing the account?
  • Does it work with a local directory?

1- yes i stopped the service and then started
2- right now i checked and it is working for local directory

Others may chime in, but since it appears you are using a network share, it still seems a permissions issue.

Other things to try:

  • Use forward slashes instead of backslashes-- might not be likely to help in this case, as it works locally, but in python, backslashes are used to escape characters. Forward slashes avoids that issue.
  • map the share to a drive letter, then update the path.

Thanks @JordanCClark .

My points on network share is that, in perspective i need to open pdf and show it on pdf viewer without using webdev module. any possibilities on this

stuck from long time and didnt get any success.

I don’t think there’s a way around having to fetch the PDF from an url endpoint.

However there are many free python servers you could set up if you don’t want to have to buy the web dev module (though now you have two systems / code bases to maintain, likely in two different versions of python, this is the cost you pay instead of the cost of the web dev module). Flask or Django are the two most popular ones.

i can display pdfs in an iframe from the webapps path.
C:\Program Files\Inductive Automation\Ignition\webserver\webapps\main
Maybe putting a symlink in there… but ive no idea if that is will work withough the other permissions.
there are documents about sharing/mappings. ive never read them tho
https://docs.inductiveautomation.com/display/DOC81/Mapping+a+Network+Drive

That seems a bit overkill for just a pdf !

1 Like

Django sure, flask I could see setting it up in under 50 lines of code if that.

FastAPI would probably be even easier.

Or bottle, or use a proxy server like nginx, or if it’s Windows (and you’re a masochist) you could use IIS, or you could stand up a webserver in X other programming language of choice - there’s literally infinite options here.

Webdev is convenient because it’s attached to your ‘monolith’ Ignition instance already.

3 Likes

Yea. If costs wasn’t an option I would just get Webdev. Obviously that is not always the case which is why I recommended alternatives. It does seem like overkill but you are trying to do a workaround so it will be a bit of work lol.

Thanks @bkarabinchak.psi

So in your opinion is to create API and use it in ignition. As i will update one thing i am getting the link of network drive in tag and i only need to show it on pdf viewer so maybe for that i need to create API or if can i convert the static link into weburl if possible.

Thanks.

So i will try to use this feature and see if i find any success on the same