Domanda

Trying to get IE to quit inside of a thread. If I navigate to google.com or facebook.com it has no problem, the ie.Quit() works just fine. However, when I navigate to our company sharepoint site I get:

Error in IEThread:  (-2147352567, 'Exception occurred.', (0, None, None, None, 0, -2147467259), None
Exception in thread Thread-1:
Traceback (most recent call last):
  File "C:\python27\lib\threading.py", line 808, in __bootstrap_inner
    self.run()
  File "PepTalk.pyw", line 404, in run
    ie.Quit()
  File "C:\python27\lib\site-packages\win32com\client\dynamic.py", line 522, in __getattr__
    raise AttributeError("%s.%s" % (self._username_, attr))
AttributeError: InternetExplorer.Application.Quit

It doesn't make any sense because the AttributeError is for something that I can make the same script do with a different address. I'm running IE in it's own thread, here is my code:

class IEThread(Thread):
    def __init__(self):
        Thread.__init__(self)
        self.queue = Queue()

    def run(self):
        ie = None
        pythoncom.CoInitialize()
        try:
            ie = Dispatch('InternetExplorer.Application')
            ie.Visible = 1
            url = self.queue.get()
            print 'Visiting...', url
            ie.Navigate(url)
            while ie.Busy:
                time.sleep(0.1)
        except Exception, e:
            print "Error in IEThread: ", e

        if ie is not None:
            ie.Quit()

ieThread = IEThread()
ieThread.start()
url = 'https://company.sharepoint.com/company/Shared Documents/Weekly Pep Talk/2013/'
ieThread.queue.put(url)

Any ideas why this would be happening?

È stato utile?

Soluzione

The most likely explanation is that you're navigating to an Intranet Zone site, which causes IE to perform an in-place process switch (replacing the Low Integrity Internet Zone tab with a Medium Integrity Intranet Zone tab). Thus the handle you're holding no longer points to the active tab process.

There's some discussion of this issue in my IEInternals post here: http://blogs.msdn.com/b/ieinternals/archive/2011/08/03/internet-explorer-automation-protected-mode-lcie-default-integrity-level-medium.aspx

Altri suggerimenti

It is actually possible to solve this in Python by calling the Dispatch with the CLSID that is associated with the Medium Integrity Intranet Zone.

import win32com.client
from time import sleep

ie = win32com.client.Dispatch('{D5E8041D-920F-45e9-B8FB-B1DEB82C6E5E}')
ie.Navigate(intranet_url)

while ie.Busy:
    sleep(0.1)

ie.Quit()  

Works !

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top