Python scripts in IIS

J

Jon Cosby

I'm having trouble executing Python scripts in IIS. I have the error message
"%1 is not a valid Win32 application". Anyone know what this is about?

Jon Cosby
 
P

Peter Hansen

Jon said:
I'm having trouble executing Python scripts in IIS. I have the error message
"%1 is not a valid Win32 application". Anyone know what this is about?

Somewhere, something is attempting to execute an application with an
argument that contains "%1", which is normally substituted with a
variable string supplied by something else. Clearly that isn't happening
here.

Without more detail, I doubt anyone can help much more. Maybe you should
post some snippets of code. Also, if the error message actually includes
more information (e.g. such as a Python traceback would have), cut and paste
the entire output rather than just retyping a part of it (if that's what you
did).

-Peter
 
J

Jon Cosby

Peter Hansen said:
Somewhere, something is attempting to execute an application with an
argument that contains "%1", which is normally substituted with a
variable string supplied by something else. Clearly that isn't happening
here.

Without more detail, I doubt anyone can help much more. Maybe you should
post some snippets of code. Also, if the error message actually includes
more information (e.g. such as a Python traceback would have), cut and paste
the entire output rather than just retyping a part of it (if that's what you
did).

-Peter

I get the same line with all of my scripts, nothing else.

Jon
 
P

Peter Hansen

Jon said:
I get the same line with all of my scripts, nothing else.

Please go back and reread the previous sentence again. If you won't
provide some context, you won't likely get helpful answers.

I'll try again: *what* is giving you that error message? Some program
prints it, somewhere. Is it in a log file? Printed to the console?
In a popup dialog box? On the browser screen? What exact command did you
type just before you saw that error. Have you installed Python?
What version? etc etc etc...

-Peter
 
J

Jon Cosby

Peter Hansen said:
Please go back and reread the previous sentence again. If you won't
provide some context, you won't likely get helpful answers.

I'll try again: *what* is giving you that error message? Some program
prints it, somewhere. Is it in a log file? Printed to the console?
In a popup dialog box? On the browser screen? What exact command did you
type just before you saw that error. Have you installed Python?
What version? etc etc etc...

Sorry. It's in the browser window. The script does not execute. I have "Show
friendly http error messages" set to false in Internet Explorer. As it
happens on all of the scripts, I can't single out one command. I have
ActiveState's build of Python 2.3, and don't recall running into this
previously, but there might be something in the IIS configuration I'm
overlooking.

Jon
 
S

Scott F

Sorry. It's in the browser window. The script does not execute. I
have "Show friendly http error messages" set to false in Internet
Explorer. As it happens on all of the scripts, I can't single out
one command. I have ActiveState's build of Python 2.3, and don't
recall running into this previously, but there might be something
in the IIS configuration I'm overlooking.

Go to the Properties of the (Default) Web site, Home Directory tab,
Configuration button. On the Mappings tab, add a mapping for Python in
the form

<pathtopython>\python.exe %s %s

Use your actual pathtopython and don't substitute anything for %s %s.

Should work fine.

Scott
 
J

Jon Cosby

Scott F said:
Go to the Properties of the (Default) Web site, Home Directory tab,
Configuration button. On the Mappings tab, add a mapping for Python in
the form

<pathtopython>\python.exe %s %s

Use your actual pathtopython and don't substitute anything for %s %s.

Should work fine.
Thanks. I had left out the trailing arguments. What is "%s" for, anyway?

Jon
 
S

Scott F

Thanks. I had left out the trailing arguments. What is "%s" for,
anyway?

I don't know. With MS I usually don't bother finding out if I can get
things to work.

Scott
 
G

Gandalf

Jon said:
Thanks. I had left out the trailing arguments. What is "%s" for, anyway?

Jon
Sorry, I just read this message. I did not the beginning of this thread.
Jon, why don't you register
Python as an ActiveX scripting language? You can download and install
pywin32 extensions:

https://sourceforge.net/projects/pywin32/

then you can run this script:

site-packages\win32comext\axscript\client\pyscript.py

This will register Python as an ActiveX scripting language.
Then you can create an ASP page like this (index.asp):

<%@ Language=Python %>
<%
lst = [0,1,2,3]
Response.write(str(lst))
%>

I think it is better (and faster) to use Python as an ActiveX scripting
language then to use it as a CGI program.
Best,

G
 
A

Andrew Clover

Jon Cosby said:
Thanks. I had left out the trailing arguments. What is "%s" for, anyway?

It gets substituted with the name of the .py file.

Note: you really want -

...python.exe -u %s %s

The -u ensures you get binary IO streams, which will become significant if
you are receiving file upload fields or returning a non-textual response
(ie. file download).
 
S

Scott F

(e-mail address removed) (Andrew Clover) wrote in

Note: you really want -

...python.exe -u %s %s

The -u ensures you get binary IO streams, which will become
significant if you are receiving file upload fields or returning a
non-textual response (ie. file download).

Can you reference the documentation for the -u argument?

Thanks.

Scott
 
S

Scott F

Peter Hansen said:
"python -h" will show you.

Right for python, but not for IIS. E.g., in

<path>python.exe %s %s

The first %s stands for the script name, and the second %s stands for
_all_ the arguments. This is not normal substitution. That's why %s
needs to be used, not even %S (capitalized).

Actually, Robert Brewer's response is more to the point. Security is
more troublesome with the above.
 
P

Peter Hansen

Scott said:
Right for python, but not for IIS.

Wasn't the -u used as an option to Python in the example you were
asking about?

Andy had written this (re-posted here for reference):

Looks like a Python option to me, not an IIS one...

-Peter
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,902
Latest member
Elena68X5

Latest Threads

Top