473,322 Members | 1,417 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

handling pywintypes.error exceptions

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:
win32net.NetUseAdd(None, 1, {'remote':r'\\foo\bar','local':'X 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:
win32net.NetUseAdd(None, 1,

{'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

Jul 18 '05 #1
1 8658
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

"Lucas Machado" <LM*******@gmail.com> wrote in message
news:11**********************@f14g2000cwb.googlegr oups.com...
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:
win32net.NetUseAdd(None, 1, {'remote':r'\\foo\bar','local':'X 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:
win32net.NetUseAdd(None, 1,

{'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


----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
----= East and West-Coast Server Farms - Total Privacy via Encryption =----
Jul 18 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Steffan Surdek | last post by:
Hi All! We are interfacing an ASP page with a COM object. In the COM object, if there is a condition that makes it not possible to perform the requested action, an exception is raised that can...
4
by: Ken Fine | last post by:
No joy on Macromedia's boards after a few days; maybe someone can help me here. I got an excellent string handling function off of planet-source-code.com that converts text strings to proper...
1
by: Bill S. | last post by:
Hi, I a stored procedure that inserts a record into a table as below. The insert works OK, but if the insert violates a unique indewx constraint on one of the columns, the proc terminates...
59
by: kk_oop | last post by:
Hi. I wanted to use exceptions to handle error conditions in my code. I think doing that is useful, as it helps to separate "go" paths from error paths. However, a coding guideline has been...
3
by: vj | last post by:
Please let me know how can i handle any kind of error conditions with a single (condition and continue handler). I need to catch any kind of exception thrown in the procedure with a single (...
0
by: Janjan | last post by:
I want to catch any soapexception error by these method. My question is Does creating an instance from assembly name can retrieve exception errors from UI? I have read documents on handling...
3
by: Robert Rotstein | last post by:
It appears that exception handling at the top-most level of a C# program, in the static void Main() method, differs depending on whether the program is run in debug mode or not. That is, code such...
3
by: Antoon Pardon | last post by:
In a number of cases I have a program that looks like the following. for case in all_cases: try: treat(case) except Exception, ErrInfo: generate_traceback() The idea is to get as much...
7
by: Gouri.Mahajan7 | last post by:
Hello, I am new to asp.net. when i close the browser programmatically I am getting an application error at the line given below. <param name="SessionID" value="<%= Session %>"/> because of...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.