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

J

John Machin

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:
(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
 
G

Gabriel Genellina

| >>> 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
 
J

John Machin

| >>> 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
 
J

John Machin

En Sun, 11 Feb 2007 01:57:52 -0300, John Machin <[email protected]>
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
 
D

Dennis Lee Bieber

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

PythonWin 2.4.3 (#69, Apr 11 2006, 15:32:42) [MSC v.1310 32 bit (Intel)]
on win32.
Portions Copyright 1994-2004 Mark Hammond ([email protected]) -
see 'Help/About PythonWin' for further copyright information.
This is Windows XP Pro SP2. The user with the problem is _not_ an

XP Pro, sp2, from my user account.
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.
It has them, but unless one is part of a Windows Domain network, the
control panel to /define a user/ at that level is not available.

Now, can I remember where I found it last week... From an admin
account (or a command shell that was started as an admin using "run
as"), execute lusrmgr.msc

Under "Groups", I show 11 categories. One of those is "Power User",
and I did add myself to that a week ago (I'd remove myself to test, but
that may require a log-off/log-on to reset the active account, and I'm
in the midst of a 7 hour video rendering -- applying both brightness and
unsharp masking to a 1-hour AVI takes time). However, given this
information, you should be able to set yourself up.

XP HOME, I think, does not support the extra groups.
--
Wulfraed Dennis Lee Bieber KD6MOG
(e-mail address removed) (e-mail address removed)
HTTP://wlfraed.home.netcom.com/
(Bestiaria Support Staff: (e-mail address removed))
HTTP://www.bestiaria.com/
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,982
Messages
2,570,185
Members
46,738
Latest member
JinaMacvit

Latest Threads

Top