By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
449,098 Members | 923 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 449,098 IT Pros & Developers. It's quick & easy.

os.tmpfile() -> permission denied (Win XP)

P: n/a
Hi,

Here's what's happening:

Python 2.5 (r25:51908, Sep 19 2006, 09:52:17) [MSC v.1310 32 bit
(Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
| >>import os
| >>os.tmpfile()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
OSError: [Errno 13] Permission denied

but tempfile.mkstemp() works:
>>import tempfile
tempfile.mkstemp()
(3, 'c:\\docume~1\\sjm\\locals~1\\temp\\tmpnfuk9i')

This is Windows XP Pro SP2. The user with the problem is _not_ an
administrator. It works OK when logged on as an administrator. I am
using the mode which enables having multiple users logged on and
switching between them.

The problem happens with Pythons back to 2.2. Python 2.1 on Windows
doesn't seem to have a tmpfile() function in the os module.

On a Windows 2000 SP4 box, with a "Power User" [part way between
administrator and vanilla user] Python 2.3.5 os.tmpfile() works OK.
AFAICT Win XP doesn't have this intermediate level of user.

Questions:
1. Before I start checking what permissions who has to do what to
which, what directory is it likely to be trying to open the temp file
in? C:\WINDOWS\TEMP....?
2. What is the general advice about whether to use os.tmpfile() or the
functions in the tempfile module? I'm presuming that as os.tmpfile()
is ultimately calling tmpfile() in the C stdio library, nobody would
have gone to the effort of making the tempfile module just to
reproduce stdio functionality, but AFAICT there's no guidance in the
docs. Maybe I should be talking to the authors of the package that is
using os.tmpfile() :-)

TIA for any clues,
John

Feb 11 '07 #1
Share this Question
Share on Google+
3 Replies


P: n/a
En Sun, 11 Feb 2007 01:57:52 -0300, John Machin <sj******@lexicon.net>
escribió:
| >>os.tmpfile()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
OSError: [Errno 13] Permission denied

1. Before I start checking what permissions who has to do what to
which, what directory is it likely to be trying to open the temp file
in? C:\WINDOWS\TEMP....?
You could analyze the source, but usually I find easier to use FILEMON:
http://www.sysinternals.com

--
Gabriel Genellina

Feb 11 '07 #2

P: n/a
On Feb 11, 4:15 pm, "Gabriel Genellina" <gagsl...@yahoo.com.arwrote:
En Sun, 11 Feb 2007 01:57:52 -0300, John Machin <sjmac...@lexicon.net>
escribió:
| >>os.tmpfile()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
OSError: [Errno 13] Permission denied
1. Before I start checking what permissions who has to do what to
which, what directory is it likely to be trying to open the temp file
in? C:\WINDOWS\TEMP....?

You could analyze the source,
I have already followed the twisty little passages: os.tmpfile() is
really nt.tempfile(), but there is no Modules/ntmodule.c (Modules/
posixmodule.c does a Jekyll & Hyde trick). (nt|posix)module calls
tmpfile(), which is (as I mentioned) in the C stdio library. How can I
analyse the source of that? Have Microsoft had a rush of blood to the
head and gone open source overnight??
but usually I find easier to use FILEMON:http://www.sysinternals.com
Thanks, I'll try that.

Cheers,
John

Feb 11 '07 #3

P: n/a
On Feb 11, 4:33 pm, "John Machin" <sjmac...@lexicon.netwrote:
On Feb 11, 4:15 pm, "Gabriel Genellina" <gagsl...@yahoo.com.arwrote:
En Sun, 11 Feb 2007 01:57:52 -0300, John Machin <sjmac...@lexicon.net>
escribió:
| >>os.tmpfile()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
OSError: [Errno 13] Permission denied
1. Before I start checking what permissions who has to do what to
which, what directory is it likely to be trying to open the temp file
in? C:\WINDOWS\TEMP....?
You could analyze the source,

I have already followed the twisty little passages: os.tmpfile() is
really nt.tempfile(), but there is no Modules/ntmodule.c (Modules/
posixmodule.c does a Jekyll & Hyde trick). (nt|posix)module calls
tmpfile(), which is (as I mentioned) in the C stdio library. How can I
analyse the source of that? Have Microsoft had a rush of blood to the
head and gone open source overnight??
but usually I find easier to use FILEMON:http://www.sysinternals.com

Thanks, I'll try that.
While Filemon is still alive, it's been superceded by Procmon, which
combines filemon + regmon + plus new goodies. I tried procmon.

And the result of an administrator user doing os.tmpfile():
281773 4:50:14.8607126 PM python.exe 2716 CreateFile C:\t2ks SUCCESS
Access: Generic Read/Write, Delete, Disposition: Create, Options:
Synchronous IO Non-Alert, Non-Directory File, Delete On Close,
Attributes: N, ShareMode: Read, Write, Delete, AllocationSize:
3,184,748,654,057,488,384
[big snip]

*** AARRGGHH It's creating the file in the *ROOT* directory ***

A quick google for "tmpfile root directory" reveals that this is a
"popular" problem on Windows. See e.g. http://bugs.mysql.com/bug.php?
id=3998 which has several users corroborating the story, plus this
handy hint:
"""
But MSDN says (ms-help://MS.MSDNQTR.2003APR.1033/vclib/html/
_crt_tmpfile.htm):
-------
The tmpfile function creates a temporary file and returns a pointer to
that stream. The temporary file is created in the root directory. To
create a temporary file in a directory other than the root, use tmpnam
or tempnam in conjunction with fopen.
"""

I wonder why my environment has entries for TMP and TEMP (both
pointing to the same path, and it sure ain't the root directory) --
must be one of those "haha fooled you" tricks :-(

Regards,
John

Feb 11 '07 #4

This discussion thread is closed

Replies have been disabled for this discussion.