Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7444017
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T11:25:33+00:00 2026-05-29T11:25:33+00:00

I am using Python 3.2.2, and building a Tkinter interface to do some Active

  • 0

I am using Python 3.2.2, and building a Tkinter interface to do some Active Directory updating. I am having trouble trying to handle pythoncom.com_error exceptions.

I grabbed some code from here:
http://code.activestate.com/recipes/303345-create-an-account-in-ms-active-directory/

However, I use the following (straight from the above site) handle the exceptions raised:

except pythoncom.com_error,(hr,msg,exc,arg):

This code is consistent with many of the sites I have seen that handle these exceptions, however with Python 3.2.2, I get a syntax error if I include the comma after “pythoncom.com_error”. If I remove the comma, the program starts, but then when the exception is raised, I get other exceptions because “hr”, “msg” etc are not defined as global variables.

If I remove the comma and all of the bits in the brackets, then it all works well, except I can’t see exactly what happens in the exception, which I want so I can pass through the actual error message from AD.

Does anyone know how to handle these pythoncom exceptions properly in Python 3.2.2?

Thanks in advance!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T11:25:34+00:00Added an answer on May 29, 2026 at 11:25 am

    You simply need to use the modern except-as syntax, I think:

    import pythoncom
    import win32com
    import win32com.client
    
    location = 'fred'
    try:
        ad_obj=win32com.client.GetObject(location)
    except pythoncom.com_error as error:
        print (error)
        print (vars(error))
        print (error.args)
        hr,msg,exc,arg = error.args
    

    which produces

    (-2147221020, 'Invalid syntax', None, None)
    {'excepinfo': None, 'hresult': -2147221020, 'strerror': 'Invalid syntax', 'argerror': None}
    (-2147221020, 'Invalid syntax', None, None)
    

    for me [although I’m never sure whether the args order is really what it looks like, so I’d probably refer to the keys explicitly; someone else may know for sure.]

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am working on building an inverted index using Python. I am having some
I am having trouble building a Python function that launches TkInter objects, with commands
I am having trouble building a working version of Python with ctypes using the
So, I'm building a GUI in Python using Tkinter which will be used to,
I'm building a centralized desktop application using Python/wxPython. One of the requirements is User
I am building an IRC bot using Python. I require the bot to be
I am building a tile based app in Python using pyglet/openGL wherein I'll need
I am trying to self-learn developing Web applications using Python as backend. Since I
I'm currently using Python 2.7 + wxPython 2.8.11 on my windows machine. While trying
I'm building a scientific application in Python and considering using Amazon EC2 to run

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.