handling pywintypes.error exceptions

L

Lucas Machado

I'm using the win32 api to map samba shares, and I'm having trouble
handling some exceptions. In my script there are 2 possible exceptions
when the script attempts to map a share:
Traceback (most recent call last):
File "<stdin>", line 1, in ?
pywintypes.error: (53, 'NetUseAdd', 'The network path was not found.')

This exception occurs when '\\foo\bar' is not an existing share. Also,
when a drive letter is already in use the following occurs:
{'remote':r'\\some_server\share','local':'Y:'})
Traceback (most recent call last):
File "<stdin>", line 1, in ?
pywintypes.error: (85, 'NetUseAdd', 'The local device name is already
in use.')

I know the exception raised in these cases is "pywintypes.error", but
how can i differentiate between the two exceptions? Being able to do
this is critical for my script....

Thanks in advance,
--Lucas Machado
 
R

Roger Upole

You can capture the extra exception data like this.

try:
....win32net.NetUseAdd(None, 1, {'remote':r'\\foo\bar','local':'X
except pywintypes.error,details:
....err_code=details[0]
....<do something based on the error code>

Roger
 

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

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top