handling pywintypes.error exceptions

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Lucas Machado

    #1

    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:
    [color=blue][color=green][color=darkred]
    >>> win32net.NetUse Add(None, 1, {'remote':r'\\f oo\bar','local' :'X[/color][/color][/color]
    Traceback (most recent call last):
    File "<stdin>", line 1, in ?
    pywintypes.erro r: (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:
    [color=blue][color=green][color=darkred]
    >>> win32net.NetUse Add(None, 1,[/color][/color][/color]
    {'remote':r'\\s ome_server\shar e','local':'Y:' })
    Traceback (most recent call last):
    File "<stdin>", line 1, in ?
    pywintypes.erro r: (85, 'NetUseAdd', 'The local device name is already
    in use.')

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

    Thanks in advance,
    --Lucas Machado

  • Roger Upole

    #2
    Re: handling pywintypes.erro r exceptions

    You can capture the extra exception data like this.

    try:
    ....win32net.Ne tUseAdd(None, 1, {'remote':r'\\f oo\bar','local' :'X
    except pywintypes.erro r,details:
    ....err_code=de tails[0]
    ....<do something based on the error code>

    Roger

    "Lucas Machado" <LMachado1@gmai l.com> wrote in message
    news:1110050058 .490815.176610@ f14g2000cwb.goo glegroups.com.. .[color=blue]
    > 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:
    >[color=green][color=darkred]
    >>>> win32net.NetUse Add(None, 1, {'remote':r'\\f oo\bar','local' :'X[/color][/color]
    > Traceback (most recent call last):
    > File "<stdin>", line 1, in ?
    > pywintypes.erro r: (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:
    >[color=green][color=darkred]
    >>>> win32net.NetUse Add(None, 1,[/color][/color]
    > {'remote':r'\\s ome_server\shar e','local':'Y:' })
    > Traceback (most recent call last):
    > File "<stdin>", line 1, in ?
    > pywintypes.erro r: (85, 'NetUseAdd', 'The local device name is already
    > in use.')
    >
    > I know the exception raised in these cases is "pywintypes.err or", but
    > how can i differentiate between the two exceptions? Being able to do
    > this is critical for my script....
    >
    > Thanks in advance,
    > --Lucas Machado
    >[/color]



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

    Comment

    Working...