[Python-Dev] os.access versus os.exist

Robert Brewer fumanchu at amor.org
Mon Nov 15 22:50:10 CET 2004


Me:
> > > It would be awfully nice (on posix platforms, for my 
> > > use-case) to find out whether a file is inaccessible
> > > due to permission restrictions, or due to non-existence.

Guido van Rossum:
> > Why can't you solve this by doing a stat() when access() 
> > returns False?

Me:
> In my current case, stat() gives an error (even though the 
> file exists):
> 
> OSError: [Errno 2] No such file or directory:
> u'S:/Scans/Projects/2004/TJ/04TJ0267.jpg'
> 
> Running the same stat() call in the interpreter (as opposed 
> to inside my mod_python app) gives no such error; I get normal stat
> output, so the file does exist. I figured since the app was running
> as LocalSystem it was a permissions issue. [One quick sanity check
> later] Yes, if I run Apache2 under my account, stat() does not error.
> 
> Hm. I see now I'm following the wrong issue. It has more to 
> do with how Windows shares mapped drives between users (it doesn't).
> If I use the UNC path, I don't have an issue.

Bah. Spoke too soon. I still have the issue even if I use UNC paths.

In Pythonwin interactive session (my logon):
   os.stat() returns a tuple,
   os.path.exists() returns True, and
   os.access() returns True.

Inside the app (running under LocalSystem on the same Win2k machine):
   os.stat() raises OSError: [Errno 2] No such file or directory,
   os.path.exists() returns False, and
   os.access() returns False.


Robert Brewer
MIS
Amor Ministries
fumanchu at amor.org


More information about the Python-Dev mailing list