[Twisted-Python]How to display python script output and php path
I'm using an existing twisted python script to serve my Web pages (see below) on Linux. When I set the URL to point to a python script (see example below), the script executes well. I see the output result in the shell window but nothing is shown in the browser window. Could you point me out what is missing in this script to display the output of a script? I looked in the mailing list archive and could not find my answer. And how could I change the filter path to the php executable. Actually the path is set to "/usr/bin/php4" and I want to set it to "/usr/local/bin/php". Thanks. ------------------------------------------------------ Script: import sys if sys.platform == 'win32': from twisted.internet import win32eventreactor win32eventreactor.install() from twisted.python import log from twisted.internet import reactor from twisted.web import static, server, twcgi, script, xmlrpc, resource from twisted.internet import utils import os import Interpreter import Dispatcher def main(): log.startLogging(sys.stdout) print "Starting up Selenium Server..." root = resource.Resource() # The proxy server (aka "The Funnel") if sys.platform == 'win32': path = os.path.join(os.getcwd(),"cgi-bin","nph-proxy.exe") else: path = os.path.join(os.getcwd(),"cgi-bin","nph-proxy.cgi") proxy = twcgi.CGIScript(path) root.putChild("AUT",proxy) #The followoing are all available from /selenium-driver/ # * Selenium BrowserBot html, css, and javascript (/selenium-driver/*) # * Selenese driver (/selenium-driver/driver/) # * XML-RPC listener (/selenium-driver/RP2/) driver = static.File("./selenium_driver") driver.ignoreExt('.rpy') driver.indexNames=['index.rpy'] driver.processors = {'.rpy': script.ResourceScript, '.php': twcgi.PHPScript, '.py': script.PythonScript} root.putChild('selenium-driver', driver) reactor.listenTCP(10001, server.Site(root)) reactor.run() if __name__ == '__main__': main() --------------------------- Example of script: #!/usr/bin/env python print 'Allo' [
Normand Savard wrote:
I'm using an existing twisted python script to serve my Web pages (see below) on Linux. When I set the URL to point to a python script (see example below), the script executes well. I see the output result in the shell window but nothing is shown in the browser window. Could you point me out what is missing in this script to display the output of a script? I looked in the mailing list archive and could not find my answer.
And how could I change the filter path to the php executable. Actually the path is set to "/usr/bin/php4" and I want to set it to "/usr/local/bin/php".
Thanks.
Two days ago I sent this post to this list (notice that I removed the script to not overload this email) without any answer maybe because my question was not clear enough. So I try again. I have a Twisted Web server to serve my HTML pages. When I point my URL to an external Python script, the script is executed because I can see the return value of this script in the shell where I started Twisted Web. But the return value is not displayed in the browser window. Does someone know why Twisted Web server does not display the return value of my Python script in the browser window? Or what is the output stream to print to in my python script for Twisted to display the text in the browser? Any help would be really appreciate. Or if someone could point me out to some Twisted documentation about this topic. Thanks for your time. Norm
On Fri, 07 Apr 2006 09:58:24 -0400, Normand Savard
Normand Savard wrote:
I'm using an existing twisted python script to serve my Web pages (see below) on Linux. When I set the URL to point to a python script (see example below), the script executes well. I see the output result in the shell window but nothing is shown in the browser window. Could you point me out what is missing in this script to display the output of a script? I looked in the mailing list archive and could not find my answer.
And how could I change the filter path to the php executable. Actually the path is set to "/usr/bin/php4" and I want to set it to "/usr/local/bin/php".
Thanks. Two days ago I sent this post to this list (notice that I removed the script to not overload this email) without any answer maybe because my question was not clear enough. So I try again. I have a Twisted Web server to serve my HTML pages. When I point my URL to an external Python script, the script is executed because I can see the return value of this script in the shell where I started Twisted Web. But the return value is not displayed in the browser window.
Does someone know why Twisted Web server does not display the return value of my Python script in the browser window? Or what is the output stream to print to in my python script for Twisted to display the text in the browser?
Any help would be really appreciate. Or if someone could point me out to some Twisted documentation about this topic.
If the output is going to a terminal window, it's not being sent to the right place. I am not sure what kind of external Python script you are trying to use, but it sounds like it is using "print" and expecting the results to end up on a web page. Generally speaking, this isn't how dynamic resources in Twisted Web work - you need to write something to the request object for it to end up in the browser. Hope this helps, Jean-Paul
Jean-Paul Calderone wrote:
If the output is going to a terminal window, it's not being sent to the right place. I am not sure what kind of external Python script you are trying to use, but it sounds like it is using "print" and expecting the results to end up on a web page. Generally speaking, this isn't how dynamic resources in Twisted Web work - you need to write something to the request object for it to end up in the browser.
Thanks for your answer. Yes I used a simple print in my script. Could you point me out some documentation and/or examples on how to do that? I appreciate your help. Norm
Jean-Paul Calderone wrote:
If the output is going to a terminal window, it's not being sent to the right place. I am not sure what kind of external Python script you are trying to use, but it sounds like it is using "print" and expecting the results to end up on a web page. Generally speaking, this isn't how dynamic resources in Twisted Web work - you need to write something to the request object for it to end up in the browser.
Thanks. It makes me understand some elements about Twisted I didn't understand first. Norm
On Wednesday 05 April 2006 09:54, Normand Savard wrote:
Example of script:
#!/usr/bin/env python
print 'Allo'
I think this should be: --- from twisted.web import resource class AlloResource(resource.Resource): def render(self, request): return "Allo" resource = AlloResource() --- Mike.
Mike Pelletier wrote:
On Wednesday 05 April 2006 09:54, Normand Savard wrote:
Example of script:
#!/usr/bin/env python
print 'Allo'
I think this should be:
--- from twisted.web import resource
class AlloResource(resource.Resource): def render(self, request): return "Allo"
resource = AlloResource() ---
Mike.
Mike, Thanks a lot. It will help. Norm
participants (3)
-
Jean-Paul Calderone
-
Mike Pelletier
-
Normand Savard