473,387 Members | 3,820 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

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 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
10 1676
Hi!
..func( is not defined...
@-salutations
--
Michel Claveau

Oct 17 '06 #2
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
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

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

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
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
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

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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: abhilash agarwal | last post by:
hi all!! pl help me i m getting a run time error "memory address .... refer to this location....... memory could not be written at this location....." ..... means some memory address when...
16
by: | last post by:
Hi all, I have a website running on beta 2.0 on server 2003 web sp1 and I keep getting the following error:- Error In:...
4
by: XML newbie: Urgent pls help! | last post by:
I am using VB.Net. My program is to connect to a remote IPAddress. Once, it verifies the login information it should display the SessionID and enable some button . I appreciate your help and thanku...
4
by: Jason Richmeier | last post by:
I keep encountering an error message while trying to build a solution that I cannot seem to get around. I cannot figure out what the error is trying to tell me as there does not appear to be much...
9
by: Jerry C | last post by:
I am trying to write to the errorlog and I am getting the error Cannot open log for source 'Application'. You may not have write access. This is the code: Dim Logevent As New...
0
by: =?Utf-8?B?R2lvcmdpbw==?= | last post by:
Hi, I need some urgent help and your help is very much appreciated. I have a control in a directory named components and I am trying to load that control and add it to the page and when I run...
1
by: psantosh12 | last post by:
Hello Frnds Please need help to resolve error.......... it is very very urgent........ The error is Runtime Error Description: An application error occurred on the server. The current custom...
6
by: =?Utf-8?B?UGF1bCBQcmV3ZXR0?= | last post by:
Hi - I have 4 webservers in my webfarm. All Win2k3 web edition. Before yesterday, none of them were service packed. I have now applied SP2 to two of them, and I'm getting a very weird MSDTC...
7
by: =?Utf-8?B?SmVycnkgQw==?= | last post by:
I am using this code to get groups for a user and getting a error (5) on the GetAuthorizationGroups() function . There are two domains. This function works on the local domain but does not work...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.