os listdir access denied when run as a service

Larry Bates larry.bates at websafe.com
Thu May 25 18:57:56 CEST 2006


Thomas Thomas wrote:
> 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..
> 
> 
> -----------------------------------------------------
> Thomas Thomas
> 
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



More information about the Python-list mailing list