COM Error -- Urgent help

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

    #1

    COM Error -- Urgent help

    HI all,

    I have a problem in accesing COM objects in threads. To be precise,
    lets assume that I have a class GenericFunction s which is defined as
    follows:


    import win32com.client , pythoncom, thread
    ie=win32com.cli ent.Dispatch('i nternetexplorer .application')
    ie.Visible=1


    class GenericFunction s:


    def __init__(self):
    print "In Constructor of Generic Functions"


    def MyNavigate(self ,dest):
    ie.Navigate(des t)


    Now there is another file Main.py which is defined as follows:


    import win32com.client , pythoncom, thread
    from GenericFunction s import *
    obj = GenericFunction s()


    class Mainclass:
    def __init__(self);
    print "In Constructor of Main class"


    def threadFunction( self,dest):
    pythoncom.CoIni tialize()
    d=pythoncom.CoG etInterfaceAndR eleaseStream(s,
    pythoncom.IID_I Dispatch)
    my_ie=win32com. client.Dispatch (d)
    obj.func(dest) # this is gving an error.
    pythoncom.CoUni nitialize()


    if __name__ == "__main__":


    s=pythoncom.CoM arshalInterThre adInterfaceInSt ream(pythoncom. IID_IDispatch,i ­e)

    thread.start_ne w_thread(self.n av, (s,'www.google. com')


    Basically, I want to access object of GenericFunction s class inside
    threadFunction( ). However I was able to execute
    my_ie.Navigate( "google.com "). But that was not I wanted. I am not
    knowing where the error is....
    Please let me know the solution ASAP...


    Teja.P

  • Méta-MCI

    #2
    Re: COM Error -- Urgent help

    Hi!


    ..func( is not defined...


    @-salutations
    --
    Michel Claveau



    Comment

    • Teja

      #3
      Re: COM Error -- Urgent help

      Méta-MCI wrote:
      Hi!
      >
      >
      .func( is not defined...
      >
      >
      @-salutations
      --
      Michel Claveau
      I am sorry. By func(dest) I meant MyNavigate(dest ). Can u please help
      me out...

      Thnks,
      Teja.P

      Comment

      • Fredrik Lundh

        #4
        Re: COM Error -- Urgent help

        Teja wrote:
        I am sorry. By func(dest) I meant MyNavigate(dest ). Can u please help
        me out...
        nobody here can read your mind. please post the code you're actually
        using, *and* the error you're getting.

        </F>

        Comment

        • Teja

          #5
          Re: COM Error -- Urgent help


          Fredrik Lundh wrote:
          Teja wrote:
          >
          I am sorry. By func(dest) I meant MyNavigate(dest ). Can u please help
          me out...
          >
          nobody here can read your mind. please post the code you're actually
          using, *and* the error you're getting.
          >
          </F>
          Thnks for your immediate reply.

          Here is the code:

          I have a class GenericFunction s which is defined as
          follows:

          import win32com.client , pythoncom, thread
          ie=win32com.cli ent.Dispatch('i nternetexplorer .application')
          ie.Visible=1

          class GenericFunction s:

          def __init__(self):
          print "In Constructor of Generic Functions"

          def MyNavigate(self ,dest):
          ie.Navigate(des t)


          Now there is another file Main.py which is defined as follows:

          import win32com.client , pythoncom, thread
          from GenericFunction s import *
          obj = GenericFunction s()

          def threadFunction( self,dest):
          pythoncom.CoIni tialize()
          d=pythoncom.CoG etInterfaceAndR eleaseStream(s,
          pythoncom.IID_I Dispatch)
          my_ie=win32com. client.Dispatch (d)
          obj.MyNavigate( dest) # this is gving an error.
          pythoncom.CoUni nitialize()

          if __name__ == "__main__":

          s=pythoncom.CoM arshalInterThre adInterfaceInSt ream(pythoncom. IID_IDispatch,i ­­e)

          thread.start_ne w_thread(self.n av, (s,'www.google. com')

          I am getting an attribute error

          Comment

          • Teja

            #6
            Re: COM Error -- Urgent help


            Dennis Lee Bieber wrote:
            On 17 Oct 2006 00:58:59 -0700, "Teja" <tejovathi.p@gm ail.comdeclaime d
            the following in comp.lang.pytho n:
            >
            thread.start_ne w_thread(self.n av, (s,'www.google. com')

            I am getting an attribute error
            >
            That can not be the REAL code... I'd expect a syntax error... You
            have mismatched parens on that line!
            --
            Wulfraed Dennis Lee Bieber KD6MOG
            wlfraed@ix.netc om.com wulfraed@bestia ria.com

            (Bestiaria Support Staff: web-asst@bestiaria. com)
            HTTP://www.bestiaria.com/
            Hi,

            Ya its a copy paste error... But can u please let me know what is the
            reason for attribute error and how to rectify it??

            Thnks,
            Regards
            Teja.P

            Comment

            • Fredrik Lundh

              #7
              Re: COM Error -- Urgent help

              Teja wrote:
              s=pythoncom.CoM arshalInterThre adInterfaceInSt ream(pythoncom. IID_IDispatch,i ­­e)
              >
              thread.start_ne w_thread(self.n av, (s,'www.google. com')
              >
              I am getting an attribute error
              the traceback tells you what attribute Python was looking for, and may also provide
              additional clues. can you post the traceback too? make sure you include all of it.

              </F>



              Comment

              • Diez B. Roggisch

                #8
                Re: COM Error -- Urgent help

                Teja wrote:
                >
                Dennis Lee Bieber wrote:
                >On 17 Oct 2006 00:58:59 -0700, "Teja" <tejovathi.p@gm ail.comdeclaime d
                >the following in comp.lang.pytho n:
                >>
                thread.start_ne w_thread(self.n av, (s,'www.google. com')
                >
                I am getting an attribute error
                >>
                >That can not be the REAL code... I'd expect a syntax error... You
                >have mismatched parens on that line!
                >--
                >Wulfraed Dennis Lee Bieber KD6MOG
                >wlfraed@ix.netc om.com wulfraed@bestia ria.com
                >HTTP://wlfraed.home.netcom.com/
                >(Bestiaria Support Staff: web-asst@bestiaria. com)
                >HTTP://www.bestiaria.com/
                >
                Hi,
                >
                Ya its a copy paste error... But can u please let me know what is the
                reason for attribute error and how to rectify it??
                How many times need you a beating with a clue-stick?

                Post the _actual_ code, not something that closely resembles it - in _your_
                opinion....

                Post the error message!!!!

                And before you do all this, read:



                Diez

                Comment

                • Teja

                  #9
                  Re: COM Error -- Urgent help


                  Diez B. Roggisch wrote:
                  Teja wrote:
                  >

                  Dennis Lee Bieber wrote:
                  On 17 Oct 2006 00:58:59 -0700, "Teja" <tejovathi.p@gm ail.comdeclaime d
                  the following in comp.lang.pytho n:
                  >
                  thread.start_ne w_thread(self.n av, (s,'www.google. com')

                  I am getting an attribute error
                  >
                  That can not be the REAL code... I'd expect a syntax error... You
                  have mismatched parens on that line!
                  --
                  Wulfraed Dennis Lee Bieber KD6MOG
                  wlfraed@ix.netc om.com wulfraed@bestia ria.com

                  (Bestiaria Support Staff: web-asst@bestiaria. com)
                  HTTP://www.bestiaria.com/
                  Hi,

                  Ya its a copy paste error... But can u please let me know what is the
                  reason for attribute error and how to rectify it??
                  >
                  How many times need you a beating with a clue-stick?
                  >
                  Post the _actual_ code, not something that closely resembles it - in _your_
                  opinion....
                  >
                  Post the error message!!!!
                  >
                  And before you do all this, read:
                  >

                  >
                  Diez

                  OK Ok .. Here is the final code thats giving an error:

                  GenericFunction s.py
                  ----------------------------------

                  import win32com.client , pythoncom, thread
                  ie=win32com.cli ent.Dispatch('i nternetexplorer .application')
                  ie.Visible=1

                  class GenericFunction s:
                  def __init__(self):
                  print "In Constructor of Generic Functions"
                  def MyNavigate(self ,dest):
                  ie.Navigate(des t)
                  ---------------------------------------------------------------------------------------------------------------
                  MainThread.py
                  --------------------------

                  import win32com.client , pythoncom, thread
                  from GenericFunction s import *
                  obj = GenericFunction s()
                  import sys,traceback


                  def threadFunction( s,dest):
                  pythoncom.CoIni tialize()
                  try:
                  d=pythoncom.CoG etInterfaceAndR eleaseStream(s,
                  pythoncom.IID_I Dispatch)
                  my_ie=win32com. client.Dispatch (d)
                  #d.MyNavigate(d est)
                  obj.MyNavigate( dest) # this is gving an error.
                  except:
                  my_ie = None
                  print traceback.print _exc(file= sys.stdout)
                  pythoncom.CoUni nitialize()

                  if __name__ == "__main__":

                  s=pythoncom.CoM arshalInterThre adInterfaceInSt ream(pythoncom. IID_IDispatch,i e)

                  thread.start_ne w_thread(thread Function, (s,'www.google. com'))


                  -----------------------------------------------------------------------------------------------------------------------------
                  And here is the error:

                  Traceback (most recent call last):
                  File "C:\Documen ts and Settings\dzxbrn \Desktop\Stop Test\13
                  Oct\MainThread. py", line 13, in threadFunction
                  obj.MyNavigate( dest) # this is gving an error.
                  File "C:\Documen ts and Settings\dzxbrn \Desktop\Stop Test\13
                  Oct\GenericFunc tions.py", line 9, in MyNavigate
                  ie.Navigate(des t)
                  File "C:\Python24\Li b\site-packages\win32c om\client\dynam ic.py", line
                  489, in __getattr__
                  raise AttributeError, "%s.%s" % (self._username _, attr)
                  AttributeError: internetexplore r.application.N avigate
                  None


                  This is highly urgent and important... Please help me out....

                  Thnks & Regards,
                  Tejovathi.P

                  Comment

                  • Neil Hodgson

                    #10
                    Re: COM Error -- Urgent help

                    Teja:
                    ie=win32com.cli ent.Dispatch('i nternetexplorer .application')
                    ie.Visible=1
                    >
                    class GenericFunction s:
                    def __init__(self):
                    print "In Constructor of Generic Functions"
                    def MyNavigate(self ,dest):
                    ie.Navigate(des t)
                    You are using an interface created on the main thread here.
                    >...
                    d=pythoncom.CoG etInterfaceAndR eleaseStream(s,
                    pythoncom.IID_I Dispatch)
                    my_ie=win32com. client.Dispatch (d)
                    #d.MyNavigate(d est)
                    obj.MyNavigate( dest) # this is gving an error.
                    After all the trouble of marshalling the interface into this thread
                    you aren't using it. Pass my_ie to MyNavigate. I also had some errors
                    before changing from thread to threading.

                    Neil

                    Comment

                    • Teja

                      #11
                      Re: COM Error -- Urgent help

                      This is the trae back ,can you help me please.....

                      Traceback (most recent call last):
                      File "C:\Documen ts and Settings\dzxbrn \Desktop\Stop Test\13
                      Oct\MainThread. py", line 13, in threadFunction
                      obj.MyNavigate( dest) # this is gving an error.
                      File "C:\Documen ts and Settings\dzxbrn \Desktop\Stop Test\13
                      Oct\GenericFunc tions.py", line 9, in MyNavigate
                      ie.Navigate(des t)
                      File "C:\Python24\Li b\site-packages\win32c om\client\dynam ic.py", line
                      489, in __getattr__
                      raise AttributeError, "%s.%s" % (self._username _, attr)
                      AttributeError: internetexplore r.application.N avigate
                      None
                      Fredrik Lundh wrote:
                      Teja wrote:
                      >
                      s=pythoncom.CoM arshalInterThre adInterfaceInSt ream(pythoncom. IID_IDispatch,i ­­e)

                      thread.start_ne w_thread(self.n av, (s,'www.google. com')

                      I am getting an attribute error
                      >
                      the traceback tells you what attribute Python was looking for, and may also provide
                      additional clues. can you post the traceback too? make sure you includeall of it.

                      </F>

                      Comment

                      Working...