By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,285 Members | 1,691 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,285 IT Pros & Developers. It's quick & easy.

COM Error -- Urgent help

P: n/a
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.appl ication')
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

Oct 17 '06 #1
Share this Question
Share on Google+
10 Replies


P: n/a
Hi!
..func( is not defined...
@-salutations
--
Michel Claveau

Oct 17 '06 #2

P: n/a
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

Oct 17 '06 #3

P: n/a
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>

Oct 17 '06 #4

P: n/a

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

import win32com.client, pythoncom, thread
ie=win32com.client.Dispatch('internetexplorer.appl ication')
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

Oct 17 '06 #5

P: n/a

Dennis Lee Bieber wrote:
On 17 Oct 2006 00:58:59 -0700, "Teja" <te*********@gmail.comdeclaimed
the following in comp.lang.python:
thread.start_new_thread(self.nav, (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
wl*****@ix.netcom.com wu******@bestiaria.com
HTTP://wlfraed.home.netcom.com/
(Bestiaria Support Staff: we******@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

Oct 17 '06 #6

P: n/a
Teja wrote:
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>

Oct 17 '06 #7

P: n/a
Teja wrote:
>
Dennis Lee Bieber wrote:
>On 17 Oct 2006 00:58:59 -0700, "Teja" <te*********@gmail.comdeclaimed
the following in comp.lang.python:
thread.start_new_thread(self.nav, (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
wl*****@ix.netcom.com wu******@bestiaria.com
HTTP://wlfraed.home.netcom.com/
(Bestiaria Support Staff: we******@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:

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

Diez
Oct 17 '06 #8

P: n/a

Diez B. Roggisch wrote:
Teja wrote:

Dennis Lee Bieber wrote:
On 17 Oct 2006 00:58:59 -0700, "Teja" <te*********@gmail.comdeclaimed
the following in comp.lang.python:

thread.start_new_thread(self.nav, (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
wl*****@ix.netcom.com wu******@bestiaria.com
HTTP://wlfraed.home.netcom.com/
(Bestiaria Support Staff: we******@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:

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.appl ication')
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

Oct 17 '06 #9

P: n/a
Teja:
ie=win32com.client.Dispatch('internetexplorer.appl ication')
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
Oct 17 '06 #10

P: n/a
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
Fredrik Lundh wrote:
Teja wrote:
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 includeall of it.

</F>
Oct 17 '06 #11

This discussion thread is closed

Replies have been disabled for this discussion.