COM Error -- Urgent help

T

Teja

HI all,

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


import win32com.client, pythoncom, thread
ie=win32com.client.Dispatch('internetexplorer.application')
ie.Visible=1


class GenericFunctions:


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


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


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


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


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


def threadFunction(self,dest):
pythoncom.CoInitialize()
d=pythoncom.CoGetInterfaceAndReleaseStream(s,
pythoncom.IID_IDispatch)
my_ie=win32com.client.Dispatch(d)
obj.func(dest) # this is gving an error.
pythoncom.CoUninitialize()


if __name__ == "__main__":


s=pythoncom.CoMarshalInterThreadInterfaceInStream(pythoncom.IID_IDispatch,i­e)

thread.start_new_thread(self.nav, (s,'www.google.com')


Basically, I want to access object of GenericFunctions 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
 
F

Fredrik Lundh

Teja said:
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>
 
T

Teja

Fredrik said:
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 GenericFunctions which is defined as
follows:

import win32com.client, pythoncom, thread
ie=win32com.client.Dispatch('internetexplorer.application')
ie.Visible=1

class GenericFunctions:

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

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


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

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

def threadFunction(self,dest):
pythoncom.CoInitialize()
d=pythoncom.CoGetInterfaceAndReleaseStream(s,
pythoncom.IID_IDispatch)
my_ie=win32com.client.Dispatch(d)
obj.MyNavigate(dest) # this is gving an error.
pythoncom.CoUninitialize()

if __name__ == "__main__":

s=pythoncom.CoMarshalInterThreadInterfaceInStream(pythoncom.IID_IDispatch,i­­e)

thread.start_new_thread(self.nav, (s,'www.google.com')

I am getting an attribute error
 
F

Fredrik Lundh

Teja said:
s=pythoncom.CoMarshalInterThreadInterfaceInStream(pythoncom.IID_IDispatch,i­­e)

thread.start_new_thread(self.nav, (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>
 
T

Teja

Dennis said:
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
(e-mail address removed) (e-mail address removed)
HTTP://wlfraed.home.netcom.com/
(Bestiaria Support Staff: (e-mail address removed))
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
 
T

Teja

Diez said:
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:

http://www.catb.org/~esr/faqs/smart-questions.html

Diez


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

GenericFunctions.py
----------------------------------

import win32com.client, pythoncom, thread
ie=win32com.client.Dispatch('internetexplorer.application')
ie.Visible=1

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

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


def threadFunction(s,dest):
pythoncom.CoInitialize()
try:
d=pythoncom.CoGetInterfaceAndReleaseStream(s,
pythoncom.IID_IDispatch)
my_ie=win32com.client.Dispatch(d)
#d.MyNavigate(dest)
obj.MyNavigate(dest) # this is gving an error.
except:
my_ie = None
print traceback.print_exc(file= sys.stdout)
pythoncom.CoUninitialize()

if __name__ == "__main__":

s=pythoncom.CoMarshalInterThreadInterfaceInStream(pythoncom.IID_IDispatch,ie)

thread.start_new_thread(threadFunction, (s,'www.google.com'))


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

Traceback (most recent call last):
File "C:\Documents and Settings\dzxbrn\Desktop\Stop Test\13
Oct\MainThread.py", line 13, in threadFunction
obj.MyNavigate(dest) # this is gving an error.
File "C:\Documents and Settings\dzxbrn\Desktop\Stop Test\13
Oct\GenericFunctions.py", line 9, in MyNavigate
ie.Navigate(dest)
File "C:\Python24\Lib\site-packages\win32com\client\dynamic.py", line
489, in __getattr__
raise AttributeError, "%s.%s" % (self._username_, attr)
AttributeError: internetexplorer.application.Navigate
None


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

Thnks & Regards,
Tejovathi.P
 
N

Neil Hodgson

Teja:
ie=win32com.client.Dispatch('internetexplorer.application')
ie.Visible=1

class GenericFunctions:
def __init__(self):
print "In Constructor of Generic Functions"
def MyNavigate(self,dest):
ie.Navigate(dest)

You are using an interface created on the main thread here.
...
d=pythoncom.CoGetInterfaceAndReleaseStream(s,
pythoncom.IID_IDispatch)
my_ie=win32com.client.Dispatch(d)
#d.MyNavigate(dest)
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
 
T

Teja

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

Traceback (most recent call last):
File "C:\Documents and Settings\dzxbrn\Desktop\Stop Test\13
Oct\MainThread.py", line 13, in threadFunction
obj.MyNavigate(dest) # this is gving an error.
File "C:\Documents and Settings\dzxbrn\Desktop\Stop Test\13
Oct\GenericFunctions.py", line 9, in MyNavigate
ie.Navigate(dest)
File "C:\Python24\Lib\site-packages\win32com\client\dynamic.py", line
489, in __getattr__
raise AttributeError, "%s.%s" % (self._username_, attr)
AttributeError: internetexplorer.application.Navigate
None
 
D

Dennis Lee Bieber

import win32com.client, pythoncom, thread
ie=win32com.client.Dispatch('internetexplorer.application')
ie.Visible=1

class GenericFunctions:
def __init__(self):
print "In Constructor of Generic Functions"
def MyNavigate(self,dest):
ie.Navigate(dest)

Why is this defined as a class? Especially since your "ie" object is
a module global. It would make more sense as:

class GenericFunctions:
def __init__(self):
self.ie = win32com.client.Dispatch(...)
self.ie.Visible = 1
def MyNavigate(self, dest):
self.ie.Navigate(dest)

---------------------------------------------------------------------------------------------------------------
MainThread.py
--------------------------

import win32com.client, pythoncom, thread
from GenericFunctions import *
obj = GenericFunctions()
import sys,traceback
-----------------------------------------------------------------------------------------------------------------------------
And here is the error:

Traceback (most recent call last):
File "C:\Documents and Settings\dzxbrn\Desktop\Stop Test\13
Oct\MainThread.py", line 13, in threadFunction
obj.MyNavigate(dest) # this is gving an error.
File "C:\Documents and Settings\dzxbrn\Desktop\Stop Test\13
Oct\GenericFunctions.py", line 9, in MyNavigate
ie.Navigate(dest)
File "C:\Python24\Lib\site-packages\win32com\client\dynamic.py", line
489, in __getattr__
raise AttributeError, "%s.%s" % (self._username_, attr)
AttributeError: internetexplorer.application.Navigate
None
Well... It says that "internetexplorer.application" does not have a
Navigate method...

Python has a very nice interactive command line mode... Have you
tried the absolute minimum commands to see what comes up? That is, skip
all the threading stuff while testing... PythonWin is even nice enough
to list the methods available. No "Navigate" shows up, but I did find:

"Navigate2" in the PythonWin pop-up assistant...
--
Wulfraed Dennis Lee Bieber KD6MOG
(e-mail address removed) (e-mail address removed)
HTTP://wlfraed.home.netcom.com/
(Bestiaria Support Staff: (e-mail address removed))
HTTP://www.bestiaria.com/
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,226
Members
46,815
Latest member
treekmostly22

Latest Threads

Top