Importing WMI module into Python CGI script fails

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

    Importing WMI module into Python CGI script fails


    I'm working with IIS on W2K server. I'm trying to
    use module "wmi" in a CGI script but with no success.

    The following works:

    import cgitb; cgitb.enable()
    cgi.test()


    .... but the following isn't working:

    import cgitb; cgitb.enable()
    import wmi ## fails here, with msg "wmi undefined"
    cgi.test()


    Any ideas? I can import all the other modules (e.g. sys)
    except "wmi". Also, when I run the same script in IDLE
    (cgi stuff removed), it works. Sys.path has all the needed
    directories, including script's directory, and WMI's
    directory.




  • Peter Hansen

    #2
    Re: Importing WMI module into Python CGI script fails

    MK wrote:[color=blue]
    >
    > I'm working with IIS on W2K server. I'm trying to
    > use module "wmi" in a CGI script but with no success.
    >
    > The following works:
    >
    > import cgitb; cgitb.enable()
    > cgi.test()
    >
    > ... but the following isn't working:
    >
    > import cgitb; cgitb.enable()
    > import wmi ## fails here, with msg "wmi undefined"
    > cgi.test()[/color]

    Does it really just say "wmi undefined"? If not, please
    cut and paste the precise traceback which you really get.

    -Peter

    Comment

    • MK

      #3
      Re: Importing WMI module into Python CGI script fails


      "Peter Hansen" <peter@engcorp. com> wrote

      [...]

      Hello Peter! This is what I get back in browser's window:





      com_error


      Python 2.2.2: C:\python\pytho n.exe
      Sun Jul 20 20:45:23 2003

      A problem occurred in a Python script. Here is the sequence of function
      calls leading up to the error, in the order they occurred.

      ----------------------------------------------------------------------------
      ----

      C:\python\testc gi\index.pycgi
      2 import cgitb; cgitb.enable()

      3 import wmi [MK comment: this line colored with a bright color!]

      4 import sys

      5

      6 cgi.test()

      wmi undefined

      ----------------------------------------------------------------------------
      ----

      C:\python\testc gi\wmi.py
      114 # Do just enough to ensure constants are available

      115 #

      116 obj = win32com.client .GetObject ("winmgmts:" ) [MK comment: colored
      with a bright color!]

      117 win32com.client .gencache.Ensur eDispatch (obj._oleobj_)

      118 del obj

      obj undefined, win32com = <module 'win32com' from
      'C:\python\lib\ site-packages\win32c om\__init__.pyc '>, win32com.client =
      <module 'win32com.clien t' from
      'C:\python\lib\ site-packages\win32c om\client\__ini t__.pyc'>,
      win32com.client .GetObject = <function GetObject at 0x00A42DA8>

      ----------------------------------------------------------------------------
      ----

      C:\python\lib\s ite-packages\win32c om\client\__ini t__.py in
      GetObject(Pathn ame='winmgmts:' , Class=None, clsctx=23)
      71 return GetActiveObject (Class, clsctx)

      72 else:

      73 return Moniker(Pathnam e, clsctx) [MK comment: colored with a
      bright color!]

      74

      75 def GetActiveObject (Class, clsctx = pythoncom.CLSCT X_ALL):

      global Moniker = <function Moniker at 0x00A3D210>, Pathname = 'winmgmts:',
      clsctx = 23

      ----------------------------------------------------------------------------
      ----

      C:\python\lib\s ite-packages\win32c om\client\__ini t__.py in
      Moniker(Pathnam e='winmgmts:', clsctx=23)
      86 Python friendly version of GetObject's moniker functionality.

      87 """

      88 moniker, i, bindCtx = pythoncom.MkPar seDisplayName(P athname)

      89 dispatch = moniker.BindToO bject(bindCtx, None,
      pythoncom.IID_I Dispatch)

      90 return __WrapDispatch( dispatch, Pathname, clsctx = clsctx)

      moniker undefined, i undefined, bindCtx undefined, global pythoncom =
      <module 'pythoncom' from 'C:\WINNT\Syste m32\pythoncom22 .dll'>,
      pythoncom.MkPar seDisplayName = <built-in function MkParseDisplayN ame>,
      Pathname = 'winmgmts:'


      com_error: (-2147217405, 'OLE error 0x80041003', None, None)
      __doc__ = None
      __getitem__ = <bound method com_error.__get item__ of
      <pywintypes.com _error instance at 0x005A72E0>>
      __init__ = <bound method com_error.__ini t__ of <pywintypes.com _error
      instance at 0x005A72E0>>
      __module__ = 'pywintypes'
      __str__ = <bound method com_error.__str __ of <pywintypes.com _error
      instance at 0x005A72E0>>
      args = (-2147217405, 'OLE error 0x80041003', None, None)



      Comment

      • Peter Hansen

        #4
        Re: Importing WMI module into Python CGI script fails

        MK wrote:[color=blue]
        >
        > This is what I get back in browser's window:[/color]

        Browser? What are you trying to do, that runs Python code in the
        browser window? Try running your code directly instead of through
        CGI and see what happens. It's easier to debug that way.
        [color=blue]
        > C:\python\lib\s ite-packages\win32c om\client\__ini t__.py in
        > Moniker(Pathnam e='winmgmts:', clsctx=23)
        >
        > com_error: (-2147217405, 'OLE error 0x80041003', None, None)[/color]

        The above two snippets suggest that you are trying to access some
        COM object called "winmgmts:" but don't have permission. I have
        no idea about COM/ActiveX so I can't help, but perhaps someone
        else can. Searching on Google for the above error code gives
        lots of results, including:

        In the call to pWbemServices->GetObject an error of 0x80041003 is
        returned which according to MSDN documentation is

        WBEM_E_ACCESS_D ENIED
        The current user does not have permission to perform the action

        I'd suggest you (a) learn more about Python, since you don't seem
        to know how to interpret error tracebacks, and (b) describe in more
        detail what you are trying to accomplish, because the problem is
        not with the "wmi" module per se, but at a lower level, and appears
        to be related to your not having the correct user permissions for
        the object you are accessing.

        Sorry I can't help more.

        -Peter

        Comment

        • MK

          #5
          Re: Importing WMI module into Python CGI script fails

          "Peter Hansen" <peter@engcorp. com> wrote

          [...]
          [color=blue]
          > I'd suggest you (a) learn more about Python, since you don't seem
          > to know how to interpret error tracebacks, and (b) describe in more
          > detail what you are trying to accomplish, because the problem is
          > not with the "wmi" module per se, but at a lower level, and appears
          > to be related to your not having the correct user permissions for
          > the object you are accessing.[/color]


          Fair enough. Thanks for suggestions!

          I will keep digging.
          MK




          Comment

          Working...