错误“所调用的对象已与其客户端断开连接" -使用python和win32com自动化IE 8 [英] Error "The object invoked has disconnected from its clients" - automate IE 8 with python and win32com
本文介绍了错误“所调用的对象已与其客户端断开连接" -使用python和win32com自动化IE 8的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想自动化Internet Explorer 8(在Windows 7上使用python 2.7)计算机.这是我在发现帖子后的代码在SO上:
I would like to automate Internet Explorer 8 (using python 2.7 on Windows 7) machine. Here is my code after a post found on SO:
import sys, time
from win32com.client import WithEvents, Dispatch
import pythoncom
import threading
stopEvent=threading.Event()
class EventSink(object):
def OnNavigateComplete2(self,*args):
print "complete",args
stopEvent.set()
def waitUntilReady(ie):
if ie.ReadyState!=4:
while 1:
print "waiting"
pythoncom.PumpWaitingMessages()
stopEvent.wait(.2)
if stopEvent.isSet() or ie.ReadyState==4:
stopEvent.clear()
break;
if __name__ == '__main__':
time.clock()
ie=Dispatch('InternetExplorer.Application',EventSink)
ev=WithEvents(ie,EventSink)
ie.Visible=True
ie.AddressBar = True
ie.Navigate("http://www.sap.com/austria/index.epx")
waitUntilReady(ie)
对于 http://www.sap.com/austria/,我收到以下错误消息index.epx :
waiting
waiting
Traceback (most recent call last):
File "C:\Users\w\My Documents\Aptana Studio 3 Workspace\MyApp\src\GoToIdeaWindow.py", line 41, in <module>
waitUntilReady(ie)
File "C:\Users\w\My Documents\Aptana Studio 3 Workspace\MyApp\src\GoToIdeaWindow.py", line 26, in waitUntilReady
if stopEvent.isSet() or ie.ReadyState==4:
File "C:\Python27\lib\site-packages\win32com\client\__init__.py", line 463, in __getattr__
return self._ApplyTypes_(*args)
File "C:\Python27\lib\site-packages\win32com\client\__init__.py", line 456, in _ApplyTypes_
self._oleobj_.InvokeTypes(dispid, 0, wFlags, retType, argTypes, *args),
pywintypes.com_error: (-2147417848, 'The object invoked has disconnected from its clients.', None, None)
该代码非常适用于google.com或bbc.com.有人知道可能是什么原因吗?
The code works perfectly for, e.g., google.com or bbc.com. Does anybody know what could be a reason?
推荐答案
在IE9上,您需要降低安全性设置才能使脚本起作用:
On IE9, you need to lower security settings to make the script work:
IE9 -> Internet Options -> Security -> Trusted Sites : Low
IE9 -> Internet Options -> Security -> Internet : Medium + unchecked Enable Protected Mode
IE9 -> Internet Options -> Security -> Restricted Sites : unchecked Enable Protected Mode
这篇关于错误“所调用的对象已与其客户端断开连接" -使用python和win32com自动化IE 8的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文