[python-win32] Get listening ports
Hello, I'm looking for an API that can do netstat calls to return a list of listenign ports and maybe a process attached to it. Any idea ? K. ___ python-win32 mailing list python-win32@python.org http://mail.python.org/mailman/listinfo/python-win32
[python-win32] COM and threading
Running the following code results in an attribute error: Exception in thread Thread-1: Traceback (most recent call last): File "C:\Python25\lib\threading.py", line 486, in __bootstrap_inner self.run() File "testcom.py", line 10, in run print self.ie.locationUrl File "C:\Python25\Lib\site-packages\win32com\client\dynamic.py", line 500, in __getattr__ raise AttributeError, "%s.%s" % (self._username_, attr) AttributeError: InternetExplorer.Application.locationUrl It seems like the COM object isn't properly passed to the new thread. Any roundabouts? #testcom.py from win32com.client import * import pythoncom import time, threading, sys class Work(threading.Thread): def run(self): pythoncom.CoInitialize() print self.ie.locationUrl pythoncom.CoUninitialize() ie=DispatchEx("InternetExplorer.Application") ie.Navigate("http://www.google.com";) while ie.Busy: time.sleep(0.1) print ie.locationUrl w=Work() w.ie=ie w.start() w.join() ___ python-win32 mailing list python-win32@python.org http://mail.python.org/mailman/listinfo/python-win32
Re: [python-win32] COM and threading
June Kim wrote: Running the following code results in an attribute error: Exception in thread Thread-1: Traceback (most recent call last): File "C:\Python25\lib\threading.py", line 486, in __bootstrap_inner self.run() File "testcom.py", line 10, in run print self.ie.locationUrl File "C:\Python25\Lib\site-packages\win32com\client\dynamic.py", line 500, in __getattr__ raise AttributeError, "%s.%s" % (self._username_, attr) AttributeError: InternetExplorer.Application.locationUrl It seems like the COM object isn't properly passed to the new thread. Any roundabouts? Welcome to the wonderful world of COM and threading. Basically, the IWebBrowser2 object which is behind the InternetExplorer control cannot be passed as such between threads. To pass it between threads you need to marshal it and pass the resulting istream to the other thread which will then unmarshal it again. There's some sample code below which does this, but you might want to consider another approach, depending on what your app is trying to do, such as creating an IE object per thread and/or passing native Python objects between threads with Queues etc. TJG import os, sys import threading import time import pythoncom import win32com.client class Work (threading.Thread): def __init__ (self, marshalled_ie): threading.Thread.__init__ (self) self.marshalled_ie = marshalled_ie def run (self): pythoncom.CoInitialize () ie = win32com.client.Dispatch ( pythoncom.CoGetInterfaceAndReleaseStream ( self.marshalled_ie, pythoncom.IID_IDispatch ) ) print "Threaded LocationURL:", ie.LocationURL pythoncom.CoUninitialize () ie = win32com.client.Dispatch ("InternetExplorer.Application") ie.Visible = 1 ie.Navigate ("http://python.org";) while ie.Busy: time.sleep (1) print "LocationURL:", ie.LocationURL marshalled_ie = pythoncom.CoMarshalInterThreadInterfaceInStream ( pythoncom.IID_IDispatch, ie ) work = Work (marshalled_ie) work.start () work.join () ie.Quit () ___ python-win32 mailing list python-win32@python.org http://mail.python.org/mailman/listinfo/python-win32
Re: [python-win32] Get listening ports
le dahut wrote: Hello, I'm looking for an API that can do netstat calls to return a list of listenign ports and maybe a process attached to it. You need the IP Helpers API http://msdn.microsoft.com/en-us/library/ms886687.aspx I'm afraid I've never used it, though, so you'll have to scout around for examples. TJG ___ python-win32 mailing list python-win32@python.org http://mail.python.org/mailman/listinfo/python-win32
[python-win32] comtypes question: getactiveobject(ie.__clsid) says 'operation unavailsble'
New to the pywin32 user list I've read a couple of articles stating that IE doesn't register with the ROT. It was geared toward IE4, but I am not sure if I am running into this or if I am not doing something right. I question my syntax because I was certain it worked once. Both CreateObject and GetActiveObject take 'progid' which can be a clsid, or the string representation of the application's clsid eg. InternetExplorer.Application.. here is what i am trying on xp sp2 ie6-7 from comtypes.client import GetActiveObject, CreateObject ie = CreateObject('InternetExplorer.Application') ie.Visible False ie.Visible = True ie.Navigate('http://google.com') 0 (Seems good at this point) newIe = GetActiveObject('InternetExplorer.Application') 'exception in blah blah' Windows Error: ( Operation Unavailable ) The same results if I use the seemingly good ie.__clsid I've also tried passing ie._iid_ and str(ie.__clsid) and str(ie._iid_) Is this all the same problem with IE not registering with ROT? Thanks, Aaron ___ python-win32 mailing list python-win32@python.org http://mail.python.org/mailman/listinfo/python-win32