views:

21

answers:

1

Hi All,

We're programming classic ASP for a big (legacy) web application. This works quite well using WSC (Windows script components) to separate GUI from business logic; the WSCs contain the business logic, classic asp is used for displaying returned information. The WSC's return stringvalues, ADO recordsets and in some cases vbscript-objects.

Currently we're trying to switch from using VBscript inside the WSCs to Python (pyscript), so that at least the language used is modern and has more modern features available (like SOAP, ORM solutions or Memcached).

Using Python code in classic ASP works fine using pywin32 and registering Python as a scripting language, but we're experiencing two fundamental problems:

  1. In a WSC, using the "implements" tag should make all of IIS' standard objects (server, session, request, response, etc.) available to the code inside the WSC. When using Python, It just doesn't seem to work. Maybe I'm using an incorrect syntax, or I need some extra definitions in the Python code, but I can't seem to figure out how to get to these objects. More info on WSC's: http://aspalliance.com/414

  2. When an error occurs on an ASP page, the traceback is displayed in the browser and all is well. However, if an error occurs inside a WSC, there is little or no feedback to the browser. When using VBscript, Windows allows the developer to choose a debugger, and (in our case) Visual Studio kicks in and shows us the error and the line that contains the error. This works as long as you're developing locally (so the local development machine runs IIS). When using Python, nothing happens, just a very vague message in the browser, i.e:

error '80020009' Exception occurred.

I have tried different ways of working around this problem; I've tried importing win32traceutil and opening a trace collector window. The strange thing is that it will capture all of my print() statements, but not the Python error messages. It almost seems as though stdout is captured, but stderr isn't. If there are any other ways in Python to redirect or show error messages I'd like to try those too. I've even considered using a very big try..except, but besides being very bad style, the WSC contains a bunch of separate functions, and it would mean implementing try..except in every function. I really don't want to go there.

If anyone can help me with these two problems (especially nr 2 is a big showstopper for using Python in our company) it would be greatly appreciated. If there is any other way to make the Python traceback visible somehow it would be a big step forward.

By the way, I have posted this question to different mailing lists already, including the pywin32 mailing list, but until now no-one has been able to help us.

So, help me stackoverflow, you're my only hope...

Thanks All,

Erik

I have a very simple example below, consisting of an ASP page and a Python WSC, the ASP page instantiates the WSC and calls some functions from it. The Response.write will not work, because for some reason the Response object can't be used (problem nr.1), also if there is an error in the Python code, the browser will not show a tracebackor any clear message (problem nr.2). The code needs to be run under IIS ofcourse, and Python and PyWin32 need to be installed (or the activestate Python distribution, which will already include PyWin32)

python.wsc:

<?xml version="1.0" encoding="Windows-1252" ?> 
<component> 
<?component error="true" debug="true"?> 
<registration 
        description="python" 
        progid="python.WSC" 
        version="1.00" 
        classid="{F236F59E-3F6F-44EA-A374-DBFA9F90ECB3}" 

</registration> 
<public> 
        <method name="testmethod"> 
        </method> 
        <method name="helloWho"> 
                <PARAMETER name="who"/> 
        </method> 
</public>

<implements type="ASP" id="ASP"/> 

<script language="Python"> 
<![CDATA[ 
def testmethod(): 
        Response.Write('output of results converted to a string') 

def helloWho(who): 
        return "Hello "+who+"!" 
]]> 
</script> 
</component> 

ASP page:

<%@ Language=VBscript %> 
<% 
        set pythonwsc= GetObject("script:"&Server.MapPath("./python.wsc")) 
        response.write(pythonwsc.helloWho("world")&"<br>") 
        pythonwsc.testmethod() 
%> 
A: 

as for #2, you need to catch exceptions in the VBScript that calls the component. A WSC is just a com component. Ignore for a moment that there is python running when you invoke your WSC. It's just a COM component.

Errors may occur when invoking that component. It's good practice when invoking a component that may fail, to use error handling. In VBSCript, that means On Error Resume or whatever.

In Javascript, it means a try..catch clause.

Curious: why use python in the WSC? Why not just Jscript - much more mainstream, also quite modern.

Cheeso
Hi Cheeso, Thanks for your answer.Do you mean handling errors in the ASP page, or in the WSC? I'm afraid the ASP page doesn't give me any clue to what's wrong in the WSC. Handling the error in the Python code in the WSC is do-able, but when coding/debugging it's not really practical.
Rico Suave
As for why Python: Python has some very mature (web) frameworks, using it in our current project would allow us to become familiar with the language, and use it later on in other projects (web or desktop). Javascript is still mainly a client-side language. I have heard of the server side javascript implementations, but I think on the whole, Python is a safer choice.
Rico Suave