Can't access files from gateway script

Hello everyone
I have a problem opening a file in a gateway script

import os

art_path = r'C:\Users\admsaccagi\Desktop\Data_exchange\'

dirList=os.listdir(art_path)
for fname in dirList:
print(fname)

Before even getting to the file opening, it gives an error:
OSError: [Errno 20] Not a directory: 'C:\Users\admsaccagi\Desktop\Data_exchange\\'

The directory is on the local drive (not a network mapped drive) and the Ignition service is running on the same device (windows 22 server) using an administrator account

Thank you for your help

Try escaping the slashes with doubles:

art_path = r'C:\\Users\\admsaccagi\\Desktop\\Data_exchange\\'
1 Like

This doesn't guarantee that you have access; you may need to specifically grant the Ignition service user access to the directory.

That said, this seems like a bad idea. Why is the always running Ignition service relying on a folder from a specific user's desktop?

2 Likes

Please see Wiki - how to post code on this forum.

Update and a little clarification:

I do not need to access a folder on a desktop, it was only a try to avoid mapping a network drive. That said, I was able to map the drive correctly and access the file and the folder using the designer and the vision client launcher on the machine the gateway is installed on.

The problem persists on the clients outside of the gateway. It seems that the clients are looking at the local filesystem, however if the script is running on the gateway, there is something I'm missing, wether it is understanding of the process on my side or some permission on the client

Thank you

What is calling this script? A gateway event or tag event? Or a Perspective UI event? Or a Vision UI event?

The latter will use the client's local filesystem. Everything else will use the gateway filesystem, using the gateway service user's permissions.

The gateway filesystem can include mapped drives, set up at gateway startup, or scripts can use UNC paths to network locations as long as the gateway service user has permissions on the network for those. In general, a gateway or Perspective script will not have any way to access files in the filesystem of a client. Only Vision can do this.

The script is called from a Vision UI button, so that would partially explain the issue.

I now tried moving the script from the button to a tag event script on the gateway (the button triggers a memory tag) and even the same script called from a gateway timer script, completely separated from any client (just running every 1 second). Nothing, it just doesn't want to work. I'm completely lost at this point.

Probably a permissions issue with the Gateway Service user's permissions.

When you were able to access the drive from the designer and vision client on the gateway then it would use the permissions of whomever was logged in to the client (or designer) and not the Gateway Service. When you try to access the files remotely it will use the Gateway service user and if that user doesn't have permission to access the files, then it will not work.

Have you checked the gateway logs for any errors?

Are you trying to access some other user's local filesystem from the gateway? Consider not doing that. Make the gateway machine the source of truth, and have any client that needs local access share from the gateway.

The gateway service is running on the same user I was logged in when i tried using the script console. The only gateway log error i get is

OSError: [Errno 20] Not a directory:

No, I'm trying to access just a network drive. The files will be exclusively on that drive and I do not need to access the filesystem of any client

Have you tried using UNC paths in your gateway script instead of drive letter based paths? Are you sure you are escaping your backslashes properly? (Consider using java's File or Path classes to assemble and access files.)

1 Like

I have solved the issue. It was mapping the wrong network drive, the fact that it was working in the script console and from a client launched on the gateway tricked me to believe it was mapped correctly when in fact it could not be reached.
I'm using UNC paths in the ignition.conf file telling the wrapper which drive to look at.
Anyways very useful to know that a client uses its own filesystem and I should treat from now on gateway scripts as a library, not something that looks exclusively at the gateway.
Many thanks to everyone!

For posterities sake, while this works, it is fragile. If something happens and the gateway loses connection to the drive it will not automatically reconnect to the drive. The gateway will need to be restarted to do this.

You should use UNC paths directly in your scripts, it is more robust.

2 Likes

Okay, got it thank you!