Python openfile returing IOError22, even with escaped filename -


  1. i tried create new file python26 file()/open() directly inside c:\. user not have permission create new file here.

  2. expectation receive "permission denied" error. end receiving invalid file name/mode error on 1 particular host. breaking error handling of application . on other hosts doing fine.

  3. all other threads in stack on flow region: ioerror: [errno 22] invalid mode ('w') or filename point wrong file names believe not case me.

    a = file("c:\\new2.txt","w")                                   traceback (most recent call last):   file "<stdin>", line 1, in <module>                              ioerror: [errno 22] invalid mode ('w') or filename: 'c:\\new2.txt' 

whey calling file(path,"w") in windows, python calls open() or _wopen() flags o_creat | o_trunc.

both functions can return following codes (as described in msdn):

  • eacces - tried open read-only file writing, file's sharing mode not allow specified operations, or given path directory.
  • eexist - _o_creat , _o_excl flags specified, filename exists.
  • einval - invalid oflag or pmode argument.
  • emfile - no more file descriptors available (too many files open).
  • enoent - file or path not found.

as can see, eacces not option file not exists.

now let's take @ flags:

  • _o_trunc opens file , truncates 0 length; the file must have write permission. cannot specified _o_rdonly. _o_trunc used _o_creat opens existing file or creates file.

and 1 last thing:

if value other allowed oflag values specified, function generates assertion in debug mode , invokes invalid parameter handler, described in parameter validation. if execution allowed continue, function returns -1 , sets errno einval.

so, in case not eacess. instead einval (22).

you can check question how check if file can created inside given directory on ms xp/vista? , python - test directory permissions

to try find solution. can see, windows file access rights hardly can mapped posix. there no easy solution.


Comments

Popular posts from this blog

javascript - three.js lot of meshes optimization -

smartface.io - Proper way to change color scheme for whole application -

Email notification in google apps script -