The following asp script is giving me the error: "HTTP/1.1 500 Server Error"
<%@ Language = Python%>
<%
def main():
Response.Write("My first ASP script!")
main()
%>
when I run it on IIS 7.5 Windows 7 (64 bit). In the error log it simply mentions an ASP_0147 error.
I have installed Python 3.2 and Active Python 3.2.2.3 on the server and registered Python via: pyscript.py
I have enabled 32-bit applications for the server. I have also installed Python for Windows to see if that would help.
Can you suggest how I might fix this?
UPDATE:
I have managed to get this working now for python3 but I have to register with --debug, as follows:
C:\Python32\Lib\site-packages\win32comext\axscript\client>c:\Python32\python.exe
pyscript.py --debug
Requesting elevation and retrying...
Registered: Python (for debugging)
Why will it only work in debug mode? Is it safe to run in this mode?
Here's the trace when debug is enabled:
Object with win32trace dispatcher created (object=None)
in <win32com.axscript.client.pyscript.PyScript object at 0x00000000035946A0>._InvokeEx_-SetScriptSite(<PyIActiveScriptSite at 0x00000000036923B0 with obj at 0x000000000056FFD8>,) [1,0,None]
Debugging extensions (axdebug) module does not exist - debugging is disabled..
in <win32com.axscript.client.pyscript.PyScript object at 0x00000000035946A0>._QueryInterface_ with unsupported IID IActiveScriptProperty ({4954E0D0-FBC7-11D1-8410-006008C3FBFC})
in <win32com.axscript.client.pyscript.PyScript object at 0x00000000035946A0>._InvokeEx_-InitNew() [1,0,None]
in <win32com.axscript.client.pyscript.PyScript object at 0x00000000035946A0>._InvokeEx_-GetScriptDispatch(None,) [1,0,None]
in <win32com.axscript.client.pyscript.PyScript object at 0x00000000035946A0>._QueryInterface_ with unsupported IID {1D044690-8923-11D0-ABD2-00A0C911E8B2} ({1D044690-8923-11D0-ABD2-00A0C911E8B2})
in <win32com.axscript.client.pyscript.PyScript object at 0x00000000035946A0>._InvokeEx_-AddNamedItem('Response', 66) [1,0,None]
in <win32com.axscript.client.pyscript.PyScript object at 0x00000000035946A0>._InvokeEx_-AddNamedItem('Request', 66) [1,0,None]
in <win32com.axscript.client.pyscript.PyScript object at 0x00000000035946A0>._InvokeEx_-AddNamedItem('Server', 66) [1,0,None]
in <win32com.axscript.client.pyscript.PyScript object at 0x00000000035946A0>._InvokeEx_-AddNamedItem('Session', 66) [1,0,None]
in <win32com.axscript.client.pyscript.PyScript object at 0x00000000035946A0>._InvokeEx_-AddNamedItem('Application', 66) [1,0,None]
in <win32com.axscript.client.pyscript.PyScript object at 0x00000000035946A0>._InvokeEx_-AddNamedItem('ObjectContext', 66) [1,0,None]
in <win32com.axscript.client.pyscript.PyScript object at 0x00000000035946A0>._InvokeEx_-AddNamedItem('ASPGLOBALTLB', 74) [1,0,None]
in <win32com.axscript.client.pyscript.PyScript object at 0x00000000035946A0>._InvokeEx_-ParseScriptText('def main():\r\n Response.Write("My first ASP script!")\r\nmain()\r\n', None, None, 'STRIP EMBEDDED HTML COMMENTS', 0, 1, 192, 0) [1,0,None]
in <win32com.axscript.client.pyscript.PyScript object at 0x00000000035946A0>._InvokeEx_-GetScriptDispatch(None,) [1,0,None]
in <win32com.axscript.client.pyscript.PyScript object at 0x00000000035946A0>._InvokeEx_-AddNamedItem('ScriptingNamespace', 10) [1,0,None]
in <win32com.axscript.client.pyscript.PyScript object at 0x00000000035946A0>._InvokeEx_-SetScriptState(1,) [1,0,None]
in <win32com.axscript.client.pyscript.PyScript object at 0x00000000035946A0>._InvokeEx_-SetScriptState(0,) [1,0,None]
in <win32com.axscript.client.pyscript.PyScript object at 0x00000000035946A0>._InvokeEx_-Close() [1,0,None]
Thanks,
Barry
May not be the appropriate solution, in the past I've had this problem.
The recent versions of activepython seems broken for active scripting.
I was able just the version 2.5.6.10.
If the version is not important, you could try that older version.
The problem is trace
method and print
statements in the win32comext\\axscript\\client\\framework.py
because in the COM components writing to the sys.stdout
or sys.stderr
like the print
statement causes an exception for example trace("Debugging extensions (axdebug) module does not exist - debugging is disabled..")
at the line 572 of framework.py
causes an exception.
One workaround is adding import win32traceutil
in the framework.py
. The win32traceutil
redirects output to win32trace remote collector
and solve the problem without need to enabling debugging witch cause performance issues.
Another workaround is redirecting stdout
and stderr
to null, you can add following code snippet at the top of framework.py
.
f = open('nul', 'w')
sys.stdout = f
sys.stderr = f
UPDATE: The root cause and the solution
There is already a mechanism in framework.py
to prevent print and trace statements to raise an exception but the problem is in the write
method of SafeOutput
class. When tracing and debugging is not enabled, in the write method an exception occurs and win32api.OutputDebugString
in the except clause will invoke with the wrong encoding which cause an exception. Because the win32api.OutputDebugString
accept Unicode string not a multibyte character set (MBCS) as an argument.
The solution:
in the win32comext\\axscript\\client\\framework.py
in the SafeOutput
class
class SafeOutput:
softspace=1
def __init__(self, redir=None):
if redir is None: redir = sys.stdout
self.redir=redir
def write(self,message):
try:
self.redir.write(message)
except:
win32api.OutputDebugString(message.encode('mbcs'))
def flush(self):
pass
def close(self):
pass
just change
win32api.OutputDebugString(message.encode('mbcs')) # ANSI Enconding
to
win32api.OutputDebugString(message) # Unicode
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.