threading and internet explorer com

Discussion in 'Python' started by James, Jan 27, 2005.

  1. James

    James Guest

    hi,

    i'm using python 2.4 with pywin32...
    I've tried to use internet explorer control with a class.
    it was fine until i decided to inherit thread for the class...

    class domain01(threading.Thread):
    def __init__(self):
    #blabla
    threading.Thread.__init__(self)

    def run(self):
    self.ie = win32com.client.Dispatch('InternetExplorer.Application.1')
    #this line gives error if i use .start(), but if i use .run.. no error...
    self.ie.Visibble = 1
    print "running"



    xyz = domain()
    xyz.start()

    ===========
    this is what i get:
    Exception in thread Thread-23:
    Traceback (most recent call last):
    File "C:\Python24\lib\threading.py", line 442, in __bootstrap
    self.run()
    File "C:\python2exe\domain01.py", line 41, in run
    self.dologin()
    File "C:\python2exe\domain01.py", line 56, in dologin
    self.ie=win32com.client.Dispatch('InternetExplorer.Application.1')
    File "C:\Python24\Lib\site-packages\win32com\client\__init__.py",
    line 95, in Dispatch
    dispatch, userName =
    dynamic._GetGoodDispatchAndUserName(dispatch,userName,clsctx)
    File "C:\Python24\Lib\site-packages\win32com\client\dynamic.py", line
    91, in _GetGoodDispatchAndUserName
    return (_GetGoodDispatch(IDispatch, clsctx), userName)
    File "C:\Python24\Lib\site-packages\win32com\client\dynamic.py", line
    79, in _GetGoodDispatch
    IDispatch = pythoncom.CoCreateInstance(IDispatch, None, clsctx,
    pythoncom.IID_IDispatch)
    com_error: (-2147221008, 'CoInitialize has not been called.', None, None)



    =====
    but if i run:
    xyz = domain()
    xyz.run()

    ##no error! it's weird....

    anyone know how to solve this problem?

    thank you :)

    best regards,

    James
     
    James, Jan 27, 2005
    #1
    1. Advertising

  2. James

    Roger Upole Guest

    You'll need to call pythoncom.CoInitialize() in each thread.

    Roger

    "James" <> wrote in message
    news:...
    > hi,
    >
    > i'm using python 2.4 with pywin32...
    > I've tried to use internet explorer control with a class.
    > it was fine until i decided to inherit thread for the class...
    >
    > class domain01(threading.Thread):
    > def __init__(self):
    > #blabla
    > threading.Thread.__init__(self)
    >
    > def run(self):
    > self.ie = win32com.client.Dispatch('InternetExplorer.Application.1') #this
    > line gives error if i use .start(), but if i use .run.. no error...
    > self.ie.Visibble = 1
    > print "running"
    >
    >
    >
    > xyz = domain()
    > xyz.start()
    >
    > ===========
    > this is what i get:
    > Exception in thread Thread-23:
    > Traceback (most recent call last):
    > File "C:\Python24\lib\threading.py", line 442, in __bootstrap
    > self.run()
    > File "C:\python2exe\domain01.py", line 41, in run
    > self.dologin()
    > File "C:\python2exe\domain01.py", line 56, in dologin
    > self.ie=win32com.client.Dispatch('InternetExplorer.Application.1')
    > File "C:\Python24\Lib\site-packages\win32com\client\__init__.py", line
    > 95, in Dispatch
    > dispatch, userName =
    > dynamic._GetGoodDispatchAndUserName(dispatch,userName,clsctx)
    > File "C:\Python24\Lib\site-packages\win32com\client\dynamic.py", line
    > 91, in _GetGoodDispatchAndUserName
    > return (_GetGoodDispatch(IDispatch, clsctx), userName)
    > File "C:\Python24\Lib\site-packages\win32com\client\dynamic.py", line
    > 79, in _GetGoodDispatch
    > IDispatch = pythoncom.CoCreateInstance(IDispatch, None, clsctx,
    > pythoncom.IID_IDispatch)
    > com_error: (-2147221008, 'CoInitialize has not been called.', None, None)
    >
    >
    >
    > =====
    > but if i run:
    > xyz = domain()
    > xyz.run()
    >
    > ##no error! it's weird....
    >
    > anyone know how to solve this problem?
    >
    > thank you :)
    >
    > best regards,
    >
    > James





    ----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News==----
    http://www.newsfeeds.com The #1 Newsgroup Service in the World! >100,000 Newsgroups
    ---= East/West-Coast Server Farms - Total Privacy via Encryption =---
     
    Roger Upole, Jan 28, 2005
    #2
    1. Advertising

  3. James

    James Guest

    thannnnk you Roger :)
    thank you so much :)

    best regards,

    James

    Roger Upole wrote:
    > You'll need to call pythoncom.CoInitialize() in each thread.
    >
    > Roger
    >
    > "James" <> wrote in message
    > news:...
    >
    >>hi,
    >>
    >>i'm using python 2.4 with pywin32...
    >>I've tried to use internet explorer control with a class.
    >>it was fine until i decided to inherit thread for the class...
    >>
    >>class domain01(threading.Thread):
    >>def __init__(self):
    >>#blabla
    >>threading.Thread.__init__(self)
    >>
    >>def run(self):
    >>self.ie = win32com.client.Dispatch('InternetExplorer.Application.1') #this
    >>line gives error if i use .start(), but if i use .run.. no error...
    >>self.ie.Visibble = 1
    >>print "running"
    >>
    >>
    >>
    >>xyz = domain()
    >>xyz.start()
    >>
    >>===========
    >>this is what i get:
    >>Exception in thread Thread-23:
    >>Traceback (most recent call last):
    >> File "C:\Python24\lib\threading.py", line 442, in __bootstrap
    >> self.run()
    >> File "C:\python2exe\domain01.py", line 41, in run
    >> self.dologin()
    >> File "C:\python2exe\domain01.py", line 56, in dologin
    >> self.ie=win32com.client.Dispatch('InternetExplorer.Application.1')
    >> File "C:\Python24\Lib\site-packages\win32com\client\__init__.py", line
    >>95, in Dispatch
    >> dispatch, userName =
    >>dynamic._GetGoodDispatchAndUserName(dispatch,userName,clsctx)
    >> File "C:\Python24\Lib\site-packages\win32com\client\dynamic.py", line
    >>91, in _GetGoodDispatchAndUserName
    >> return (_GetGoodDispatch(IDispatch, clsctx), userName)
    >> File "C:\Python24\Lib\site-packages\win32com\client\dynamic.py", line
    >>79, in _GetGoodDispatch
    >> IDispatch = pythoncom.CoCreateInstance(IDispatch, None, clsctx,
    >>pythoncom.IID_IDispatch)
    >>com_error: (-2147221008, 'CoInitialize has not been called.', None, None)
    >>
    >>
    >>
    >>=====
    >>but if i run:
    >>xyz = domain()
    >>xyz.run()
    >>
    >>##no error! it's weird....
    >>
    >>anyone know how to solve this problem?
    >>
    >>thank you :)
    >>
    >>best regards,
    >>
    >>James

    >
    >
    >
    >
    >
    > ----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News==----
    > http://www.newsfeeds.com The #1 Newsgroup Service in the World! >100,000 Newsgroups
    > ---= East/West-Coast Server Farms - Total Privacy via Encryption =---
     
    James, Jan 28, 2005
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jan Timmer

    Asp.net and internet explorer 4.0

    Jan Timmer, Jul 18, 2003, in forum: ASP .Net
    Replies:
    5
    Views:
    373
    Gary Varga
    Jul 18, 2003
  2. Slawek

    XML and XSLT in Internet Explorer

    Slawek, Oct 20, 2003, in forum: ASP .Net
    Replies:
    1
    Views:
    351
    Slawek
    Oct 21, 2003
  3. cmay
    Replies:
    0
    Views:
    1,164
  4. Ed Hauptman
    Replies:
    7
    Views:
    1,072
    Ed Hauptman
    Aug 7, 2009
  5. John Smith
    Replies:
    1
    Views:
    164
    Evertjan.
    Mar 12, 2005
Loading...

Share This Page