IActiveScript::AddNamedItem fails with exception

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
9 messages Options
Reply | Threaded
Open this post in threaded view
|

IActiveScript::AddNamedItem fails with exception

David Manns

We have a scripting engine interface in our application. This works fine for loading/calling VBscript and Javascript scripting engines, but PythonScript fails. Specifically, it fails at :

    m_pAxsScript->AddNamedItem("application", SCRIPTITEM_NAMEDITEM)

where m_pAxsScript is the IActiveScript interface acquired through CoCreateInstance. The hresult returned is:

    80004005

which to my mind implies some kind of 'access denied' error. We are using Python 2.7.2 and Pywin32 2.7 on a Windows 7 32-bit system. We have this problem here on a test machine that was set up to match that in use at one of our customers who is now stuck being unable to run any of his Python scripts.

 

Any clues or suggestions would be gratefully received.

 

David

 


_______________________________________________
python-win32 mailing list
[hidden email]
http://mail.python.org/mailman/listinfo/python-win32
Reply | Threaded
Open this post in threaded view
|

Re: IActiveScript::AddNamedItem fails with exception

Tim Roberts
David Manns wrote:

>
> We have a scripting engine interface in our application. This works
> fine for loading/calling VBscript and Javascript scripting engines,
> but PythonScript fails. Specifically, it fails at :
>
>     m_pAxsScript->AddNamedItem("application", SCRIPTITEM_NAMEDITEM)
>
> where m_pAxsScript is the IActiveScript interface acquired through
> CoCreateInstance. The hresult returned is:
>
>     80004005
>
> which to my mind implies some kind of 'access denied' error.
>

Have you enabled Python as an Active Scripting engine?  It's not enabled
by default, because there are security issues that couldn't be
completely eliminated without disabling parts of the interpreter.  See
win32comext\axscript\client\pyscript.py.

--
Tim Roberts, [hidden email]
Providenza & Boekelheide, Inc.

_______________________________________________
python-win32 mailing list
[hidden email]
http://mail.python.org/mailman/listinfo/python-win32
Reply | Threaded
Open this post in threaded view
|

Re: IActiveScript::AddNamedItem fails with exception

Mark Hammond-4
On 3/04/2012 2:51 AM, Tim Roberts wrote:

> David Manns wrote:
>>
>> We have a scripting engine interface in our application. This works
>> fine for loading/calling VBscript and Javascript scripting engines,
>> but PythonScript fails. Specifically, it fails at :
>>
>>      m_pAxsScript->AddNamedItem("application", SCRIPTITEM_NAMEDITEM)
>>
>> where m_pAxsScript is the IActiveScript interface acquired through
>> CoCreateInstance. The hresult returned is:
>>
>>      80004005
>>
>> which to my mind implies some kind of 'access denied' error.
>>
>
> Have you enabled Python as an Active Scripting engine?  It's not enabled
> by default, because there are security issues that couldn't be
> completely eliminated without disabling parts of the interpreter.  See
> win32comext\axscript\client\pyscript.py.

Actually, it should be enabled by default - it is just that we don't
support any of the "safety options" of the active script interfaces.
Thus, the end result is that the engine is available in contexts like
Windows Scripting Host or ASP, but not in IE.

Mark
_______________________________________________
python-win32 mailing list
[hidden email]
http://mail.python.org/mailman/listinfo/python-win32
Reply | Threaded
Open this post in threaded view
|

Re: IActiveScript::AddNamedItem fails with exception

Mark Hammond-4
In reply to this post by David Manns
On 3/04/2012 1:09 AM, David Manns wrote:

> We have a scripting engine interface in our application. This works fine
> for loading/calling VBscript and Javascript scripting engines, but
> PythonScript fails. Specifically, it fails at :
>
>      m_pAxsScript->AddNamedItem("application", SCRIPTITEM_NAMEDITEM)
>
> where m_pAxsScript is the IActiveScript interface acquired through
> CoCreateInstance. The hresult returned is:
>
>      80004005
>
> which to my mind implies some kind of 'access denied' error. We are
> using Python 2.7.2 and Pywin32 2.7 on a Windows 7 32-bit system. We have
> this problem here on a test machine that was set up to match that in use
> at one of our customers who is now stuck being unable to run any of his
> Python scripts.
>
> Any clues or suggestions would be gratefully received.
>
> David

I'd suggest you:

* Execute "python win32comext\axscript\client\pyscript.py -debug" - this
will re-register the engine for debugging.

* Execute "python -m win32traceutil" - this will start a process which
is capturing messages from the COM object now it is in debug mode.

* Attempt to create and use the engine - this should cause output to be
generated.

Given the error is E_FAIL and the pyscript engine doesn't specifically
throw that, I suspect you will see a traceback.  Another alternative is
to use the IErrorInfo interfaces (I think that is what they are called)
to try and grab more information at runtime.

Mark
_______________________________________________
python-win32 mailing list
[hidden email]
http://mail.python.org/mailman/listinfo/python-win32
Reply | Threaded
Open this post in threaded view
|

Re: IActiveScript::AddNamedItem fails with exception

David Manns
Mark,

Tried doing that, but nothing comes out on the debug trace at all. Do I have
to uncomment or add any trace commands in any of the .py files, or should I
expect to see things appear on the console already?
 
Best regards,
David

-----Original Message-----
From: Mark Hammond [mailto:[hidden email]]
Sent: 03 April 2012 06:11
To: David Manns
Cc: [hidden email]
Subject: Re: [python-win32] IActiveScript::AddNamedItem fails with exception

On 3/04/2012 1:09 AM, David Manns wrote:

> We have a scripting engine interface in our application. This works
> fine for loading/calling VBscript and Javascript scripting engines,
> but PythonScript fails. Specifically, it fails at :
>
>      m_pAxsScript->AddNamedItem("application", SCRIPTITEM_NAMEDITEM)
>
> where m_pAxsScript is the IActiveScript interface acquired through
> CoCreateInstance. The hresult returned is:
>
>      80004005
>
> which to my mind implies some kind of 'access denied' error. We are
> using Python 2.7.2 and Pywin32 2.7 on a Windows 7 32-bit system. We
> have this problem here on a test machine that was set up to match that
> in use at one of our customers who is now stuck being unable to run
> any of his Python scripts.
>
> Any clues or suggestions would be gratefully received.
>
> David

I'd suggest you:

* Execute "python win32comext\axscript\client\pyscript.py -debug" - this
will re-register the engine for debugging.

* Execute "python -m win32traceutil" - this will start a process which is
capturing messages from the COM object now it is in debug mode.

* Attempt to create and use the engine - this should cause output to be
generated.

Given the error is E_FAIL and the pyscript engine doesn't specifically throw
that, I suspect you will see a traceback.  Another alternative is to use the
IErrorInfo interfaces (I think that is what they are called) to try and grab
more information at runtime.

Mark


_______________________________________________
python-win32 mailing list
[hidden email]
http://mail.python.org/mailman/listinfo/python-win32
Reply | Threaded
Open this post in threaded view
|

Re: IActiveScript::AddNamedItem fails with exception

Mark Hammond-3
On 4/04/2012 6:02 PM, David Manns wrote:
> Mark,
>
> Tried doing that, but nothing comes out on the debug trace at all. Do I have
> to uncomment or add any trace commands in any of the .py files, or should I
> expect to see things appear on the console already?

Ack - sorry about that:

> * Execute "python win32comext\axscript\client\pyscript.py -debug" - this
> will re-register the engine for debugging.

Should say "--debug" and the message it prints should say "for debugging".

Mark
_______________________________________________
python-win32 mailing list
[hidden email]
http://mail.python.org/mailman/listinfo/python-win32
Reply | Threaded
Open this post in threaded view
|

Re: IActiveScript::AddNamedItem fails with exception

David Manns
Mark,

Thanks, that's better!

Now I get this trace output:

Collecting Python Trace Output...
Object with win32trace dispatcher created (object=None)
 in <win32com.axscript.client.pyscript.PyScript instance at
0x058BF300>._InvokeEx_-SetScriptSite(<PyIActiveScriptSite at 0x05806F58 with
obj at 0x043F
F22C>,) [1,0,None]
Debugging interfaces not available - debugging is disabled..
in <win32com.axscript.client.pyscript.PyScript instance at
0x058BF300>._InvokeEx_-InitNew() [1,0,None]
in <win32com.axscript.client.pyscript.PyScript instance at
0x058BF300>._InvokeEx_-AddNamedItem(u'application', 14) [1,0,None]
**************** ASSERTION FAILED *******************
The typeKind of the object is unexpected
in <win32com.axscript.client.pyscript.PyScript instance at
0x058BF300>._InvokeEx_-Close() [1,0,None]


Hopefully that means more to you than it does to me!
 
Best regards,
David

-----Original Message-----
From: Mark Hammond [mailto:[hidden email]]
Sent: 04 April 2012 09:53
To: David Manns
Cc: [hidden email]
Subject: Re: [python-win32] IActiveScript::AddNamedItem fails with exception

On 4/04/2012 6:02 PM, David Manns wrote:
> Mark,
>
> Tried doing that, but nothing comes out on the debug trace at all. Do
> I have to uncomment or add any trace commands in any of the .py files,
> or should I expect to see things appear on the console already?

Ack - sorry about that:

> * Execute "python win32comext\axscript\client\pyscript.py -debug" -
> this will re-register the engine for debugging.

Should say "--debug" and the message it prints should say "for debugging".

Mark


_______________________________________________
python-win32 mailing list
[hidden email]
http://mail.python.org/mailman/listinfo/python-win32
Reply | Threaded
Open this post in threaded view
|

Re: IActiveScript::AddNamedItem fails with exception

Mark Hammond-3
On 4/04/2012 8:20 PM, David Manns wrote:

> Mark,
>
> Thanks, that's better!
>
> Now I get this trace output:
>
> Collecting Python Trace Output...
> Object with win32trace dispatcher created (object=None)
>   in <win32com.axscript.client.pyscript.PyScript instance at
> 0x058BF300>._InvokeEx_-SetScriptSite(<PyIActiveScriptSite at 0x05806F58 with
> obj at 0x043F
> F22C>,) [1,0,None]
> Debugging interfaces not available - debugging is disabled..
> in <win32com.axscript.client.pyscript.PyScript instance at
> 0x058BF300>._InvokeEx_-InitNew() [1,0,None]
> in <win32com.axscript.client.pyscript.PyScript instance at
> 0x058BF300>._InvokeEx_-AddNamedItem(u'application', 14) [1,0,None]
> **************** ASSERTION FAILED *******************
> The typeKind of the object is unexpected
> in <win32com.axscript.client.pyscript.PyScript instance at
> 0x058BF300>._InvokeEx_-Close() [1,0,None]
>
>
> Hopefully that means more to you than it does to me!

FWIW, the implementation is all in python in the
win32comext\axscript\client directory.  Grepping for this message shows
it as appearing in framework.py in the function GetSourceTypeInfo().
This function is attempting to locate the possible events for an item,
but it is only expecting the typeinfo to be one of TKIND_COCLASS or
TKIND_INTERFACE - sadly it doesn't report what was actually found, but
you might be able to determine that as it is your typeinfo being
examined.  Assuming your objects don't actually have events, the
simplest fix would be to just change:

                if typeKind not in [pythoncom.TKIND_COCLASS, pythoncom.TKIND_INTERFACE]:
                        RaiseAssert(winerror.E_UNEXPECTED, "The typeKind of the object is
unexpected")

to

                if typeKind not in [pythoncom.TKIND_COCLASS, pythoncom.TKIND_INTERFACE]:
                         return None

[Sadly there is also a bug in that RaiseAssert function - it has the
args wrong when creating the exception - it should read 'raise
Exception(desc, scode)', hence the E_UNEXPECTED is coming out as E_FAIL
- but that's not really a big deal...]

Let me know if that works for you and I'll make that change for the next
release.

Cheers,

Mark
_______________________________________________
python-win32 mailing list
[hidden email]
http://mail.python.org/mailman/listinfo/python-win32
Reply | Threaded
Open this post in threaded view
|

Re: IActiveScript::AddNamedItem fails with exception

David Manns
Mark,

I had to make that suggested change in two places in framework.py, plus a
change at around line 408 where FindBuildSubItemEvents tries to call
GetFuncDesc on the defaultType returned from GetDefaultSourceTypeInfo:

        defaultType = self.GetDefaultSourceTypeInfo(typeinfo)
        #***** WESTDEV EDIT ****************************
        if defaultType != None:
        #**********************************************
            index = 0
                        while 1:
                ...

This finally allows our tiny test script (just creates a text file in
c:\temp) to run successfully, so I will now pass a copy of the amended
framework.py to our customer to see if this allows him to make some progress
with his own 'real' scripts.
 
Best regards,
David


-----Original Message-----
From: Mark Hammond [mailto:[hidden email]]
Sent: 05 April 2012 00:17
To: David Manns
Cc: [hidden email]
Subject: Re: [python-win32] IActiveScript::AddNamedItem fails with exception

On 4/04/2012 8:20 PM, David Manns wrote:

> Mark,
>
> Thanks, that's better!
>
> Now I get this trace output:
>
> Collecting Python Trace Output...
> Object with win32trace dispatcher created (object=None)
>   in <win32com.axscript.client.pyscript.PyScript instance at
> 0x058BF300>._InvokeEx_-SetScriptSite(<PyIActiveScriptSite at
> 0x058BF300>0x05806F58 with
> obj at 0x043F
> F22C>,) [1,0,None]
> Debugging interfaces not available - debugging is disabled..
> in <win32com.axscript.client.pyscript.PyScript instance at
> 0x058BF300>._InvokeEx_-InitNew() [1,0,None]
> in <win32com.axscript.client.pyscript.PyScript instance at
> 0x058BF300>._InvokeEx_-AddNamedItem(u'application', 14) [1,0,None]
> **************** ASSERTION FAILED ******************* The typeKind of
> the object is unexpected in
> <win32com.axscript.client.pyscript.PyScript instance at
> 0x058BF300>._InvokeEx_-Close() [1,0,None]
>
>
> Hopefully that means more to you than it does to me!

FWIW, the implementation is all in python in the win32comext\axscript\client
directory.  Grepping for this message shows it as appearing in framework.py
in the function GetSourceTypeInfo().
This function is attempting to locate the possible events for an item, but
it is only expecting the typeinfo to be one of TKIND_COCLASS or
TKIND_INTERFACE - sadly it doesn't report what was actually found, but you
might be able to determine that as it is your typeinfo being examined.
Assuming your objects don't actually have events, the simplest fix would be
to just change:

                if typeKind not in [pythoncom.TKIND_COCLASS,
pythoncom.TKIND_INTERFACE]:
                        RaiseAssert(winerror.E_UNEXPECTED, "The typeKind of
the object is
unexpected")

to

                if typeKind not in [pythoncom.TKIND_COCLASS,
pythoncom.TKIND_INTERFACE]:
                         return None

[Sadly there is also a bug in that RaiseAssert function - it has the args
wrong when creating the exception - it should read 'raise Exception(desc,
scode)', hence the E_UNEXPECTED is coming out as E_FAIL
- but that's not really a big deal...]

Let me know if that works for you and I'll make that change for the next
release.

Cheers,

Mark


_______________________________________________
python-win32 mailing list
[hidden email]
http://mail.python.org/mailman/listinfo/python-win32