Programming Forums

Programming Forums (http://www.programmingforums.org/forumindex.php)
-   Python (http://www.programmingforums.org/forum43.html)
-   -   How to run Python scripts in a browser window (http://www.programmingforums.org/showthread.php?t=10574)

titaniumdecoy Jun 29th, 2006 4:07 PM

How to run Python scripts in a browser window
 
I am trying to figure out how to make the Windows (IIS?) system I am using display the output of .py files in a browser window rather than launch the command prompt.

I found this page, which instructed me to edit the registry, although that seems to have had no effect even after I restarted.

However, I'm not sure I did this correctly--I opened regedt32 and navigated to HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\W3SVC\Parameters\, then created a new Multi-String Value named ScriptMap with the value ".py :REG_SZ: c:\<path to python>\python.exe -u %s %s " (no parentheses). The reason I mention this is because I have almost no experience with Windows, and if anyone notices something I'm doing wrong, it would help.

Any ideas? Thanks.

Dameon Jun 29th, 2006 4:42 PM

This reference is a little more detailed.

titaniumdecoy Jun 29th, 2006 5:28 PM

The link you gave me talks about the "Internet Service Manager (ISM)". Is this a program? If so, how can I find it?

And another thing. I am writing a script that needs to access files on a T: drive which is shared over a network. I don't believe it is set up to be a web server, just such that anyone on the network can access the files on the drive. There is a separate web server that is used for hosting the website which I know has Python installed, but I don't know of any way to access files on the T: drive from it. How can I get around this?

Arevos Jun 29th, 2006 5:50 PM

Quote:

Originally Posted by titaniumdecoy
I am trying to figure out how to make the Windows (IIS?) system I am using display the output of .py files in a browser window rather than launch the command prompt.

You could always run the .py programs from a small webserver (such as CherryPy). This seems the most common way of achieving browser-based output on local machines. Google Desktop takes this approach.

Quote:

Originally Posted by titaniumdecoy
There is a separate web server that is used for hosting the website which I know has Python installed, but I don't know of any way to access files on the T: drive from it. How can I get around this?

Why not just access the T: drive using the standard file handling functions, such as os.listdir and open? Presumably, it's the filesystem's job to handle access to the network drive.

titaniumdecoy Jun 29th, 2006 6:09 PM

Quote:

Originally Posted by Arevos
You could always run the .py programs from a small webserver (such as CherryPy). This seems the most common way of achieving browser-based output on local machines. Google Desktop takes this approach.

I installed CherryPy and followed the instructions to create a Hello World page. It is displayed when I point my browser to http://localhost:8080/. My next question is, will this be accessible from any computer on the network, or only my own computer? And this only seems to work while the command prompt is open, which makes it not very useful.

Sane Jun 29th, 2006 6:35 PM

It will be accessible by any computer in the network, if localhost is replaced with your computer's private IP (eg. 192.168.0.110), found by executing the command "ipconfig" (windows only).

It will be accessible by any computer period, if localhost is replaced with your computer's public IP (eg. 64.230.61.156), and port 80 (or in your case, 8080) is forwarded to your computer's private IP (see first paragraph).

If you don't like a window always being open, save it as .pyw and it'll run as a background process (windows only).

Hope this helps.

Arevos Jun 30th, 2006 3:39 AM

Quote:

Originally Posted by titaniumdecoy
I installed CherryPy and followed the instructions to create a Hello World page. It is displayed when I point my browser to http://localhost:8080/. My next question is, will this be accessible from any computer on the network, or only my own computer?

Across the network, assuming people can get through your Windows firewall (I had some problems with Tomcat on 8080 on that regard). You could also write some code to return an error if the IP address of the computer accessing the page does not match the IP address of the computer running the server. Or just use a standard firewall, and block port 8080 from outside access.
Quote:

Originally Posted by titaniumdecoy
And this only seems to work while the command prompt is open, which makes it not very useful.

As well as Sane's suggestions, you can run CherryPy as a windows service.


All times are GMT -5. The time now is 8:04 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC