os listdir access denied when run as a service

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Thomas Thomas

    os listdir access denied when run as a service

    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=ServerIn terface.getErro rLogger()
    folder = folder.encode(' ascii') #convert path to ascii for File Method
    for filename in os.listdir(fold er):#line 25
    file=os.path.jo in(folder,filen ame)
    logger.error("l oop file :"+file);
    if os.path.isfile( file):
    logger.error("i s file :"+file);
    if ((not (file.find(".tm p")>=0)) and (not
    (file.find("~") >=0))):
    filelist.append (file)
    elif os.path.isdir(f ile):
    logger.error("f ile is a directory :"+file);
    addFolderFiles( file,filelist)

    def createFileList( files,folders,f ilelist=[]):
    logger=ServerIn terface.getErro rLogger()
    for file in files:
    file = file.encode('as cii') #convert path to ascii for File Method
    if os.path.isfile( file):
    if ((not (file.find(".tm p")>=0)) and (not (file.find("~") >=0))):
    filelist.append (file)

    for folder in folders:
    logger.error("g ot a folder :"+folder);
    logger.error("i t was in the list :"+folders.__st r__());
    addFolderFiles( folder,filelist )
    return (1,filelist)

    anything I can do about this..


    -----------------------------------------------------
    Thomas Thomas

  • Larry Bates

    #2
    Re: os listdir access denied when run as a service

    Thomas Thomas wrote:[color=blue]
    > 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=ServerIn terface.getErro rLogger()
    > folder = folder.encode(' ascii') #convert path to ascii for File Method
    > for filename in os.listdir(fold er):#line 25
    > file=os.path.jo in(folder,filen ame)
    > logger.error("l oop file :"+file);
    > if os.path.isfile( file):
    > logger.error("i s file :"+file);
    > if ((not (file.find(".tm p")>=0)) and (not
    > (file.find("~") >=0))):
    > filelist.append (file)
    > elif os.path.isdir(f ile):
    > logger.error("f ile is a directory :"+file);
    > addFolderFiles( file,filelist)
    >
    > def createFileList( files,folders,f ilelist=[]):
    > logger=ServerIn terface.getErro rLogger()
    > for file in files:
    > file = file.encode('as cii') #convert path to ascii for File Method
    > if os.path.isfile( file):
    > if ((not (file.find(".tm p")>=0)) and (not (file.find("~") >=0))):
    > filelist.append (file)
    >
    > for folder in folders:
    > logger.error("g ot a folder :"+folder);
    > logger.error("i t was in the list :"+folders.__st r__());
    > addFolderFiles( folder,filelist )
    > return (1,filelist)
    >
    > anything I can do about this..
    >
    >
    > -----------------------------------------------------
    > Thomas Thomas
    >[/color]
    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

    Comment

    • Ian Parker

      #3
      Re: os listdir access denied when run as a service

      In message <mailman.6178.1 148529545.27775 .python-list@python.org >,
      Thomas Thomas <thomas@eforms. co.nz> writes[color=blue]
      >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=ServerIn terface.getErro rLogger()
      > folder = folder.encode(' ascii') #convert path to ascii for File Method
      > for filename in os.listdir(fold er):#line 25
      > file=os.path.jo in(folder,filen ame)
      > logger.error("l oop file :"+file);
      > if os.path.isfile( file):
      > logger.error("i s file :"+file);
      > if ((not (file.find(".tm p")>=0)) and (not
      >(file.find("~" )>=0))):
      > filelist.append (file)
      > elif os.path.isdir(f ile):
      > logger.error("f ile is a directory :"+file);
      > addFolderFiles( file,filelist)
      >
      >def createFileList( files,folders,f ilelist=[]):
      > logger=ServerIn terface.getErro rLogger()
      > for file in files:
      > file = file.encode('as cii') #convert path to ascii for File Method
      > if os.path.isfile( file):
      > if ((not (file.find(".tm p")>=0)) and (not (file.find("~") >=0))):
      > filelist.append (file)
      >
      > for folder in folders:
      > logger.error("g ot a folder :"+folder);
      > logger.error("i t was in the list :"+folders.__st r__());
      > addFolderFiles( folder,filelist )
      > return (1,filelist)
      >
      >anything I can do about this..
      >
      >
      >-----------------------------------------------------
      >Thomas Thomas
      >[/color]
      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
      --
      Ian Parker

      Comment

      Working...