[python-win32] IE & DocumentComplete
Sorry if this is a repeat, but the information on the web regarding DocumentComplete and IE is not helping me find a solution. I read a 2000 thread that documentcomplete was 'broken'.. is this still the case? If not, does anyone mind sending me a snippet of some working code where it's used? I feel like I'm running in circles here. Using the Busy and readyState attributes are proving to be a waste of time without long pausing to make sure the content is actually loaded. Thanks, A ___ python-win32 mailing list [email protected] http://mail.python.org/mailman/listinfo/python-win32
[python-win32] Calling COM methods that expect arguments by reference
This question is similar to one posed by Mike Graham in a recent
thread, but I thought I'd see if I could rustle up any additional
feedback.
I'm trying to called a COM automation object using Python. The wrinkle
is that the method I need uses arguments by reference to store output
from its execution. The signature looks like this:
TileGraphic(int FileType, int Margin, intObjMargin, BSTR FileName,
BSTR DestName, float KFactor1, float KFactor2, int* Rows, int*
Columns, int* X0, int* Y0, int* XExtent, int* YExtent, long InMemory,
int* ErrorCode)
The Python code generated by makepy looks like:
def TileGraphic(self, FileType=defaultNamedNotOptArg,
Margin=defaultNamedNotOptArg, ObjMargin=defaultNamedNotOptArg,
FileName=defaultNamedNotOptArg
, DestName=defaultNamedNotOptArg, KFactor1=defaultNamedNotOptArg,
KFactor2=defaultNamedNotOptArg, Rows=pythoncom.Missing,
Columns=pythoncom.Missing
, X0=pythoncom.Missing, Y0=pythoncom.Missing,
XExtent=pythoncom.Missing, YExtent=pythoncom.Missing,
InMemory=defaultNamedNotOptArg
, ErrorCode=pythoncom.Missing):
return self._ApplyTypes_(125, 1, (24, 0), ((3, 1), (3, 1), (3, 1),
(8, 1), (8, 1), (4, 1), (4, 1), (16387, 2), (16387, 2), (16387, 2),
(16387, 2), (16387, 2), (16387, 2), (3, 1), (16387,
2)),
'TileGraphic', None,FileType
, Margin, ObjMargin, FileName, DestName, KFactor1
, KFactor2, Rows, Columns, X0, Y0
, XExtent, YExtent, InMemory, ErrorCode)
I'm somewhat unsure how to call it. If I just pass in variables with
integer values for the by reference arguments, this is the output:
## All args after 940.0 are just variables containing integers
>>> app.TileGraphic(9, 0, 0, "Test.dxf", "Results", 1.0, 940.0, rows,
cols,
x0, y0, xExtent, yExtent, 0, ErrorCode)
ERROR: An unexpected error occurred while tokenizing input
The following traceback may be corrupted or invalid
The error message is: ('EOF in multi-line statement', (156, 0))
---
com_error Traceback (most recent call
last)
c:\users\aaron\code\ in ()
C:\Python25\lib\site-packages\pywin32-210n1-py2.5-win32.egg\win32com
\gen_py\DAE1
337F-69EF-4233-B4E3-27C348C3D9D6x0x1x0.pyc in TileGraphic(self,
FileType, Margin
, ObjMargin, FileName, DestName, KFactor1, KFactor2, Rows, Columns,
X0, Y0, XExt
ent, YExtent, InMemory, ErrorCode)
648 , Margin, ObjMargin, FileName,
DestName, KFactor
1
649 , KFactor2, Rows, Columns, X0, Y0
--> 650 , XExtent, YExtent, InMemory, ErrorCode)
651
652 def TurnLaserOff(self, CardNum=defaultNamedNotOptArg):
C:\Python25\lib\site-packages\pywin32-210n1-py2.5-win32.egg\win32com
\client\__in
it__.pyc in _ApplyTypes_(self, dispid, wFlags, retType, argTypes,
user, resultCL
SID, *args)
446 return self._get_good_object_(
447 self._oleobj_.InvokeTypes(
--> 448 dispid, 0, wFlags, retType,
argTypes, *arg
s),
449 user, resultCLSID)
450
com_error: (-2147352567, 'Exception occurred.', (0,
'winlase.Automate', 'Error d
uring Tiling', None, 0, -2147467259), None)
I have also tried using pythoncom.Missing and pythoncom.ArgNotFound
per Mark Hammond's suggestion. I thought by reference input variables
were supposed to be converted to output tuples by makepy. Am I missing
something here? If I try and execute the method without any of the
input reference variables, I get this error:
TypeError: int() argument must be a string or a number, not 'NoneType'
___
python-win32 mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-win32
Re: [python-win32] Calling COM methods that expect arguments by reference
Hi Greg, I gave your suggestion a shot, but I get the following perplexing error: TypeError: int() argument must be a string or a number, not 'NoneType' which makes me think it's still somehow expecting to get those values as input even though they're explicitly set to be outputs in the generated file. I'll dig a bit deeper tomorrow to see what I can come up with. Thanks, Aaron On Aug 10, 2009, at 2:30 PM, Greg Antal wrote: Aaron: From the Python definition you show, PythonCOM is going to treat your call-by-reference arguments as output values whether they're supposed to be or not. This is for all the parameters defined with type (16387, 2). When you have parameters identified like that, your Python call has to treat them as return values, not as calling arguments. In your case, that means your call should look like Rows, Cols, X0, Y0, Xext, Yext, ErrCode = app.TileGraphic (9, 0, 0, "Test.dxf", "Results", 1.0, 940.0, 0) . Of course, that may not actually solve all your problems. Mike Graham and I had ongoing trouble even after we got the calling sequence right, for completely different reasons. If that happens to you, I'm afraid you'll have to get advice from someone much wiser than I. (There are a lot of them monitoring this list, fortunately.) - Greg Antal Gregory W. Antal Senior Technical Advisor ATA Engineering, Inc. 11995 El Camino Real, Suite 200 San Diego, CA 92130 www.ata-e.com [email protected] 858-480-2072 (Phone) 858-792-8932 (Fax) Aaron Hoover wrote, On 8/10/2009 1:34 PM: This question is similar to one posed by Mike Graham in a recent thread, but I thought I'd see if I could rustle up any additional feedback. I'm trying to called a COM automation object using Python. The wrinkle is that the method I need uses arguments by reference to store output from its execution. The signature looks like this: TileGraphic(int FileType, int Margin, intObjMargin, BSTR FileName, BSTR DestName, float KFactor1, float KFactor2, int* Rows, int* Columns, int* X0, int* Y0, int* XExtent, int* YExtent, long InMemory, int* ErrorCode) The Python code generated by makepy looks like: def TileGraphic(self, FileType=defaultNamedNotOptArg, Margin=defaultNamedNotOptArg, ObjMargin=defaultNamedNotOptArg, FileName=defaultNamedNotOptArg , DestName=defaultNamedNotOptArg, KFactor1=defaultNamedNotOptArg, KFactor2=defaultNamedNotOptArg, Rows=pythoncom.Missing, Columns=pythoncom.Missing , X0=pythoncom.Missing, Y0=pythoncom.Missing, XExtent=pythoncom.Missing, YExtent=pythoncom.Missing, InMemory=defaultNamedNotOptArg , ErrorCode=pythoncom.Missing): return self._ApplyTypes_(125, 1, (24, 0), ((3, 1), (3, 1), (3, 1), (8, 1), (8, 1), (4, 1), (4, 1), (16387, 2), (16387, 2), (16387, 2), (16387, 2), (16387, 2), (16387, 2), (3, 1), (16387, 2)), 'TileGraphic', None,FileType , Margin, ObjMargin, FileName, DestName, KFactor1 , KFactor2, Rows, Columns, X0, Y0 , XExtent, YExtent, InMemory, ErrorCode) I'm somewhat unsure how to call it. If I just pass in variables with integer values for the by reference arguments, this is the output: ## All args after 940.0 are just variables containing integers >>> app.TileGraphic(9, 0, 0, "Test.dxf", "Results", 1.0, 940.0, rows, cols, x0, y0, xExtent, yExtent, 0, ErrorCode) ERROR: An unexpected error occurred while tokenizing input The following traceback may be corrupted or invalid The error message is: ('EOF in multi-line statement', (156, 0)) --- com_error Traceback (most recent call last) c:\users\aaron\code\ in () C:\Python25\lib\site-packages\pywin32-210n1-py2.5-win32.egg\win32com \gen_py\DAE1 337F-69EF-4233-B4E3-27C348C3D9D6x0x1x0.pyc in TileGraphic(self, FileType, Margin , ObjMargin, FileName, DestName, KFactor1, KFactor2, Rows, Columns, X0, Y0, XExt ent, YExtent, InMemory, ErrorCode) 648 , Margin, ObjMargin, FileName, DestName, KFactor 1 649 , KFactor2, Rows, Columns, X0, Y0 --> 650 , XExtent, YExtent, InMemory, ErrorCode) 651 652 def TurnLaserOff(self, CardNum=defaultNamedNotOptArg): C:\Python25\lib\site-packages\pywin32-210n1-py2.5-win32.egg\win32com \client\__in it__.pyc in _ApplyTypes_(self, dispid, wFlags, retType, argTypes, user, resultCL SID, *args) 446 return self._get_good_object_( 447 self._oleobj_.InvokeTypes( --> 448 dispid, 0, wFlags, retType, argTypes, *arg s), 449 user, resultCLSID) 450 com_error: (-2147352567, 'Exception occurred.', (0, 'winlase.Automate', 'Error d uring Tiling
[python-win32] List of keys and values
Hi Guys,
This should be dead simple.
I am just trying to find a list of all of the key value pairs held for each
message.
These are the ones that I have found so far:
- subject
- SenderName
- Recipients
- TaskDueDate
I am using this simple code snippet
import win32com.client
outlook =
win32com.client.Dispatch("Outlook.Application").GetNamespace("MAPI")
inbox = outlook.GetDefaultFolder(6) # "6" refers to the index of a folder -
in this case,
# the inbox. You can change that number
to reference
# any other folder
messages = inbox.Items
message = messages.GetLast()
then doing this for eample:
for message in messages:
print message.TaskDueDate
i was wondering what else I can get access to for a message?
many thanks in advance,
Aaron
--
Aaron Reabow
+27 83 649 7567
___
python-win32 mailing list
[email protected]
https://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
[email protected]
http://mail.python.org/mailman/listinfo/python-win32
[python-win32] automatically restart python service after crash
I developed a python service using win32serviceutil.ServiceFramework
and PythonService.exe. If the service
crashes (eg, an unhandled exception is raised) I want the service to
restart. So, I configured the service to restart
using `ChangeServiceConfig2`. Code looks like this.
```
import win32serviceutil
import win32service
import os
from . import makeWin32Service
win32serviceutil.HandleCommandLine(makeWin32Service.PreVeilService)
service_name = os.environ.get("PV_SERVICE_NAME")
win32service.ChangeServiceConfig2
hscm = win32service.OpenSCManager(None,None,win32service.SC_MANAGER_ALL_ACCESS)
try:
hs = win32service.OpenService(hscm, service_name,
win32service.SERVICE_ALL_ACCESS)
try:
win32service.ChangeServiceConfig2(hs,
win32service.SERVICE_CONFIG_FAILURE_ACTIONS_FLAG, True)
service_failure_actions = {
'ResetPeriod': 60*60, # Time in seconds after
which to reset the failure count to zero.
'RebootMsg': u'', # Not using reboot option
'Command': u'', # Not using run-command option
'Actions': [
(win32service.SC_ACTION_RESTART, 1000*5), #
first action after failure, delay in ms
(win32service.SC_ACTION_RESTART, 1000*5), #
second action after failure
(win32service.SC_ACTION_NONE, 0)#
subsequent actions after failure
]
}
win32service.ChangeServiceConfig2(hs,
win32service.SERVICE_CONFIG_FAILURE_ACTIONS, service_failure_actions)
except (win32service.error, NotImplementedError):
print "ChangeServiceConfig2 failed to set restart behavior"
finally:
win32service.CloseServiceHandle(hs)
finally:
win32service.CloseServiceHandle(hscm)
```
This does not work with vanilla pywin32. From the MSDN page for
`SERVICE_CONFIG_FAILURE_ACTIONS_FLAG`:
"If this member [fFailureActionsOnNonCrashFailures] is TRUE and the
service has configured failure actions, the failure
actions are queued if the service process terminates without
reporting a status of SERVICE_STOPPED or if it enters
the SERVICE_STOPPED state but the dwWin32ExitCode member of the
SERVICE_STATUS structure is not
ERROR_SUCCESS (0).
If this member is FALSE and the service has configured failure
actions, the failure actions are queued only if the
service terminates without reporting a status of SERVICE_STOPPED.
This setting is ignored unless the service has configured failure
actions. For information on configuring failure actions,
see ChangeServiceConfig2."
In order for the process to restart PythonService.exe needs to NOT set
status to SERVICE_STOPPED or set
dwWin32ExitCode to some non zero value. These conditions are not met
in PythonService.cpp:
```
void WINAPI service_main(DWORD dwArgc, LPTSTR *lpszArgv)
{
// ...
start = PyObject_GetAttrString(instance, "SvcRun");
if (start==NULL)
ReportPythonError(E_PYS_NO_RUN_METHOD);
else {
// Call the Python service entry point - when this returns, the
// service has stopped!
PyObject *result = PyObject_CallObject(start, NULL);
if (result==NULL)
ReportPythonError(E_PYS_START_FAILED);
else
Py_DECREF(result);
}
// We are all done.
cleanup:
// try to report the stopped status to the service control manager.
Py_XDECREF(start);
Py_XDECREF(instance);
if (pe && pe->sshStatusHandle) { // Wont be true if debugging.
if (!SetServiceStatus( pe->sshStatusHandle, &stoppedStatus ))
ReportAPIError(PYS_E_API_CANT_SET_STOPPED);
}
return;
}
```
Presumably we should do something with the return value from `SvcRun`
then conditionally report an error with
dwWin32ExitCode. Here is my patch that gives restarts when `SvcRun`
throws an exception. The ability to
let Windows handle service restarts is important; I would like to get
this fixed in upstream.
```
--- win32/src/PythonService.cpp 2017-01-07 14:58:48.156762600 -0500
+++ win32/src/PythonService.cpp 2017-01-09 03:11:08.821727300 -0500
@@ -144,6 +144,15 @@
0, // dwCheckPoint;
5000 };
+SERVICE_STATUS stoppedErrorStatus = {
+ SERVICE_WIN32_OWN_PROCESS,
+ SERVICE_STOPPED,
+0, // dwControlsAccepted,
+ERROR_SERVICE_SPECIFIC_ERROR, // dwWin32ExitCode;
+1, // dwServiceSpecificExitCode;
+0, // dwCheckPoint;
+5000 };
+
SERVICE_STATUS startingStatus = {
SERVICE_WIN32_OWN_PROCESS,
SERVICE_START_PENDING,
@@ -916,9 +925,13 @@
// Call the Python service entry point - when this returns, the
// service has stopped!
PyObject *result = PyObject_CallObject(start, NULL);
- if (result==NULL)
+ if (result==NULL) {
ReportPythonError(E_PYS_START_FAILED);
- else
+ if (pe && pe->sshStatusHandle) { // Wont be true if debugging.
+ SetServiceStatus( pe->sshStatusHandle, &stoppedErrorStatus );
+ pe->sshStatusHandle = 0; // reset so we don't attempt to set 'stopped'
+ }
+ } else
Py_DECREF(result);
}
// We a
