简体   繁体   English

ASP脚本中的Python 500服务器错误

[英]500 Server Error for Python in ASP Script

The following asp script is giving me the error: "HTTP/1.1 500 Server Error" 以下asp脚本给出了错误:“HTTP / 1.1 500服务器错误”

<%@ Language = Python%>
<%
def main():
    Response.Write("My first ASP script!")
main()
%>

when I run it on IIS 7.5 Windows 7 (64 bit). 当我在IIS 7.5 Windows 7(64位)上运行它时。 In the error log it simply mentions an ASP_0147 error. 在错误日志中,它只是提到了ASP_0147错误。

I have installed Python 3.2 and Active Python 3.2.2.3 on the server and registered Python via: pyscript.py 我在服务器上安装了Python 3.2和Active Python 3.2.2.3,并通过pyscript.py注册了Python

I have enabled 32-bit applications for the server. 我为服务器启用了32位应用程序。 I have also installed Python for Windows to see if that would help. 我还安装了Python for Windows,看看是否有帮助。

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: 我已经设法让这个为python3工作,但我必须注册--debug,如下所示:

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. 最近的activepython版本似乎因活动脚本而中断。
I was able just the version 2.5.6.10. 我只能使用版本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. 问题是win32comext\\axscript\\client\\framework.py中的trace方法和print语句,因为在COM组件中写入sys.stdoutsys.stderr就像print语句导致例外trace("Debugging extensions (axdebug) module does not exist - debugging is disabled..")异常trace("Debugging extensions (axdebug) module does not exist - debugging is disabled..")framework.py的第572行导致异常。

One workaround is adding import win32traceutil in the framework.py . 一种解决方法是在framework.py添加import win32traceutil The win32traceutil redirects output to win32trace remote collector and solve the problem without need to enabling debugging witch cause performance issues. win32traceutil将输出重定向到win32trace remote collector并解决问题,而无需启用调试导致性能问题。

Another workaround is redirecting stdout and stderr to null, you can add following code snippet at the top of framework.py . 另一种解决方法是将stdoutstderr重定向到null,您可以在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. framework.py已有一种机制可以防止print和trace语句引发异常,但问题出在SafeOutput类的write方法中。 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. 如果未启用跟踪和调试,则在write方法中会发生异常,并且except子句中的win32api.OutputDebugString将使用错误的编码进行调用,从而导致异常。 Because the win32api.OutputDebugString accept Unicode string not a multibyte character set (MBCS) as an argument. 因为win32api.OutputDebugString接受Unicode字符串而不是多字节字符集(MBCS)作为参数。

The solution: 解决方案:

in the win32comext\\axscript\\client\\framework.py in the SafeOutput class SafeOutput类的win32comext\\axscript\\client\\framework.py

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM