os listdir access denied when run as a service

T

Thomas Thomas

Hi All,

I am trying to access a mapped network drive folder. everything works fine
normally. But when i run the application as service I am getting the error

Traceback (most recent call last):
File "docBoxApp.py", line 129, in ?
File "core\PollFiles.pyc", line 332, in doPoll
File "core\PollFiles.pyc", line 47, in createFileList
File "core\PollFiles.pyc", line 25, in addFolderFiles
WindowsError: [Errno 5] Access is denied: 'G:\\DT Hot Folder test/*.*'


below is my code


def addFolderFiles(folder,filelist=[]):
logger=ServerInterface.getErrorLogger()
folder = folder.encode('ascii') #convert path to ascii for File Method
for filename in os.listdir(folder):#line 25
file=os.path.join(folder,filename)
logger.error("loop file :"+file);
if os.path.isfile(file):
logger.error("is file :"+file);
if ((not (file.find(".tmp")>=0)) and (not
(file.find("~")>=0))):
filelist.append(file)
elif os.path.isdir(file):
logger.error("file is a directory :"+file);
addFolderFiles(file,filelist)

def createFileList(files,folders,filelist=[]):
logger=ServerInterface.getErrorLogger()
for file in files:
file = file.encode('ascii') #convert path to ascii for File Method
if os.path.isfile(file):
if ((not (file.find(".tmp")>=0)) and (not (file.find("~")>=0))):
filelist.append(file)

for folder in folders:
logger.error("got a folder :"+folder);
logger.error("it was in the list :"+folders.__str__());
addFolderFiles(folder,filelist)
return (1,filelist)

anything I can do about this..
 
I

Ian Parker

Hi All,

I am trying to access a mapped network drive folder. everything works fine
normally. But when i run the application as service I am getting the error

Traceback (most recent call last):
File "docBoxApp.py", line 129, in ?
File "core\PollFiles.pyc", line 332, in doPoll
File "core\PollFiles.pyc", line 47, in createFileList
File "core\PollFiles.pyc", line 25, in addFolderFiles
WindowsError: [Errno 5] Access is denied: 'G:\\DT Hot Folder test/*.*'


below is my code


def addFolderFiles(folder,filelist=[]):
logger=ServerInterface.getErrorLogger()
folder = folder.encode('ascii') #convert path to ascii for File Method
for filename in os.listdir(folder):#line 25
file=os.path.join(folder,filename)
logger.error("loop file :"+file);
if os.path.isfile(file):
logger.error("is file :"+file);
if ((not (file.find(".tmp")>=0)) and (not
(file.find("~")>=0))):
filelist.append(file)
elif os.path.isdir(file):
logger.error("file is a directory :"+file);
addFolderFiles(file,filelist)

def createFileList(files,folders,filelist=[]):
logger=ServerInterface.getErrorLogger()
for file in files:
file = file.encode('ascii') #convert path to ascii for File Method
if os.path.isfile(file):
if ((not (file.find(".tmp")>=0)) and (not (file.find("~")>=0))):
filelist.append(file)

for folder in folders:
logger.error("got a folder :"+folder);
logger.error("it was in the list :"+folders.__str__());
addFolderFiles(folder,filelist)
return (1,filelist)

anything I can do about this..
This may be relevant. IIRC, when you run a service under the system
account it doesn't have network access. You need to run it under an
account that does have access to the drive.

Regards

Ian
 
L

Larry Bates

Thomas said:
Hi All,

I am trying to access a mapped network drive folder. everything works fine
normally. But when i run the application as service I am getting the error

Traceback (most recent call last):
File "docBoxApp.py", line 129, in ?
File "core\PollFiles.pyc", line 332, in doPoll
File "core\PollFiles.pyc", line 47, in createFileList
File "core\PollFiles.pyc", line 25, in addFolderFiles
WindowsError: [Errno 5] Access is denied: 'G:\\DT Hot Folder test/*.*'


below is my code


def addFolderFiles(folder,filelist=[]):
logger=ServerInterface.getErrorLogger()
folder = folder.encode('ascii') #convert path to ascii for File Method
for filename in os.listdir(folder):#line 25
file=os.path.join(folder,filename)
logger.error("loop file :"+file);
if os.path.isfile(file):
logger.error("is file :"+file);
if ((not (file.find(".tmp")>=0)) and (not
(file.find("~")>=0))):
filelist.append(file)
elif os.path.isdir(file):
logger.error("file is a directory :"+file);
addFolderFiles(file,filelist)

def createFileList(files,folders,filelist=[]):
logger=ServerInterface.getErrorLogger()
for file in files:
file = file.encode('ascii') #convert path to ascii for File Method
if os.path.isfile(file):
if ((not (file.find(".tmp")>=0)) and (not (file.find("~")>=0))):
filelist.append(file)

for folder in folders:
logger.error("got a folder :"+folder);
logger.error("it was in the list :"+folders.__str__());
addFolderFiles(folder,filelist)
return (1,filelist)

anything I can do about this..
Remember that services run under a different context than the
foreground login. You can configure services to run under
a user context by editing that info in the service control
panel applet under the Log On tab at the top. The default
is to run the service under Local System account which
probably doesn't have any mapped drives.

-Larry Bates
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,780
Messages
2,569,611
Members
45,273
Latest member
DamonShoem

Latest Threads

Top