<% def main...">

500 Server for Python in ASP Script

The following asp script gives me an 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, he simply mentions error ASP_0147.

I installed Python 3.2 and Active Python 3.2.2.3 on the server and registered Python via: pyscript.py

I have included 32-bit server applications. I also installed Python for Windows to see if this helps.

Can you suggest how I can fix this?

UPDATE:

I managed to get this working now for python3, but I need to register with --debug, as shown below:

 C:\Python32\Lib\site-packages\win32comext\axscript\client>c:\Python32\python.exe pyscript.py --debug Requesting elevation and retrying... Registered: Python (for debugging) 

Why does it work only in debug mode? Is it safe to work in this mode?

Here's the trace when debugging 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

+7
source share
2 answers

It may not be a suitable solution, in the past I had this problem.

Recent versions of activepython seem to be broken down into active scripts.

I managed only version 2.5.6.10.

If the version is not important, you can try this older version.

+5
source

The problem is with the trace method and print statements in win32comext\axscript\client\framework.py , because in COM components that write to sys.stdout or sys.stderr , like the print statement, an exception occurs, for example trace("Debugging extensions (axdebug) module does not exist - debugging is disabled..") at line 572 of framework.py throws an exception.

One way is to add import win32traceutil to framework.py . win32traceutil redirects the output to win32trace remote collector and solves the problem without having to enable debugging that causes performance problems.

Another solution is to redirect stdout and stderr to null, you can add the following code snippet at the top of framework.py .

  f = open('nul', 'w') sys.stdout = f sys.stderr = f 

UPDATE: root cause and solution

There is already a mechanism in framework.py to prevent print and trace SafeOutput exception, but the problem is with the write method of the SafeOutput class. When tracing and debugging are not enabled, an exception is thrown in the write method, and win32api.OutputDebugString in the except clause causes an incorrect encoding causing an exception. Since win32api.OutputDebugString takes a Unicode string, not a multibyte character set (MBCS) as an argument.

Decision:

in 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 
+2
source

All Articles