I have some problem with os exception.
In the traceback info I get only the errno without the description.
for examplem when I write:

import os;

I get the exception:

Traceback (most recent call last):
  File "<interactive input>", line 1, in <module>
WindowsError: [Error 3] : 'no-exists-dir-name/*.*'

I findout that [Error 3] in errno is map to the string: 'No such process' (return by os.strerror(3)).

Why I did not get something like:
OSErro: [Error 3] : 'No such process' 'no-exists-dir-name/*.*'

I use ActiveState ActivePython 2.5, but it is also at other version and also at the version from python.org.


Recommended Answers

All 12 Replies

You aren't getting an error message from Python. You're getting an error message from the OS. It's unlikely that Windows Error 3 has any relationship to errno 3


I understand this,
BUT why I do not get the Error at the format:
<modul-name> : [Error #] : <description> <added info>
I get only:
<modul-name> : [Error #] : <added info>

How can I know what is the exception cause?

I will give another example:

import os

The exception I got:

Traceback (most recent call last):
  File "<interactive input>", line 1, in <module>
  File "D:\Program Files\python\lib\shutil.py", line 110, in copytree
  File "D:\Program Files\python\lib\os.py", line 173, in makedirs
    mkdir(name, mode)
WindowsError: [Error 183] : 'a'

The error description the was except here:
The src and the des are the same 'a'

Why I do not get that info ?

Python is portable across a large umber of Operating Systems, so when you use OS calls, the error returned is specific for the particular OS used and generated by that OS. It would be tough for the developers of Python to cross reference all these different error numbers.

Thank for your's replays.
I do not mention before but I run this code under XP.

Jeff wrote: So you'll have to resort to careful testing.

I must do it manual?

Does it happent also at your's machines?

Please try it.

I try it at my friend's machine (XP + ActivePython, don't remember ver #) and the results were as expected, with full detailes.

What the different can be?

Can't say. In the original example,

I findout that [Error 3] in errno is map to the string: 'No such process' (return by os.strerror(3)).

Why I did not get something like:
OSErro: [Error 3] : 'No such process' 'no-exists-dir-name/*.*'

you don't get this result because Windows Error 3 'dir-name *.* does not exist' is *not* the same as errno 3: 'No such process'. Those error numbers are for different systems, and there's no relationship between them.

So if your friend's machine did somehow give you both messages -- it's a bug!


You right!
He did not get this message, errno list is not the rught error list map.
But he get some message:
"The file already exists." / "src and des are same"

what you get? same as I ?

:D Apparently, my version of Windows is more helpful than yours!

>>> import os
>>> os.listdir("Fred")

Traceback (most recent call last):
  File "<pyshell#1>", line 1, in -toplevel-
WindowsError: [Errno 3] The system cannot find the path specified: 'Fred/*.*'

So what the differen !
What can I do?

Ask microsoft will answer with "it's python problem"...

No one have solution?

Well, it's not exactly a problem to be solved, unless it's causing some other problem somewhere else. In which case, we find a workaround.

Which version of Python are you running?

I check all the version list here:
python 2.5
python 2.5.1

Now I use ActivePython- with PythonWin 2.5.1 (r251:54863, May 1 2007, 17:47:05) [MSC v.1310 32 bit (Intel)] on win32.


Hi, sorry for the late reply. But just for the sake of closing this off...

If I understand you correctly, you want a way to correctly know (and report) the nature of an error that has happened. I think what you want is exception handling.

Try wrapping your os calls with this:

... code ...
except OSError, ( errno, strerror ):
print strerror


Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.