#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2003
    Location
    Canada
    Posts
    185
    Rep Power
    0

    python.exe on the web


    on my web site I want to make a link to a python program that when the user clicks it it will execute a python program. I saw this somewhere before, but i'm not sure how it was done. i tried to simple set a href = prog.py, and i've configured my web server to accept that extension, but i keep getting an internal 500 error.

    Any ideas how to do this.
    "In theory, there is no difference between theory and practice.
    But, in practice, there is."

  2. #2
  3. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2003
    Location
    South Africa
    Posts
    9
    Rep Power
    0
    It is possible that the prog.py script doesn't produce the correct headers.
    It should at least output a Content-Type line:

    print "Content-Type: text/html"
    print # note a new line is needed before any content is sent

    This line should be the first line printed/outputted by your program.

    Another reason could be the script is causing an error/exception (I get this alot). If you have access to error-logs you might be able to see what is going on.

    Good luck
  4. #3
  5. Hello World :)
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2003
    Location
    Hull, UK
    Posts
    2,537
    Rep Power
    69
    If the page runs normally though the server then you shouldn't have any problem linking to it. That is assuming its a CGI program which as Sad said has a few requirements.

    Is your Python program in the the same dir as your html, if not then you should check the path. It may be worth bringing up that it must be in a place visable by the web server. But i dont think this is your problem since your getting a 500 error

    Mark.
    programming language development: www.netytan.com Hula

  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Nov 2003
    Posts
    624
    Rep Power
    35
    If you're using CGI - and it sounds like you are, the things you need to do are;

    Code:
    import cgi
    import cgitb
    cgitb.enable()
    
    # Change the content-type as appropriate
    print "Content-type: text/plain\n\n"
    
    # code goes here
    print "Hello from my cgi script"
    Now click the link again, and with cgi-traceback (cgitb) enabled, you should get a Python traceback as well as the error message, so you can see what went wrong. Great for development, but remember to turn it off before you finish, it's not a very pretty sight for users
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2003
    Location
    Canada
    Posts
    185
    Rep Power
    0
    i don't want to use it as a cgi script. i have all of that figured out already. what i want to do is have a python executable on my site that will executate like an execuatable. my server is supposed to interpret it and do it, so the user doesn't need to have python installed.
    "In theory, there is no difference between theory and practice.
    But, in practice, there is."

  10. #6
  11. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Nov 2003
    Posts
    624
    Rep Power
    35
    i don't want to use it as a cgi script. i have all of that figured out already.
    Ok...

    what i want to do is have a python executable
    As in, python script with executable permissions, or an .EXE file?

    on my site that will executate like an execuatable. my server is supposed to interpret it and do it
    ok, if the server interprets it, then it must be a script not an EXE. So the server runs the Python when the user clicks on a hyperlink?

    so the user doesn't need to have python installed.
    If the server is interpreting it, the user doesn't need Python installed, check.

    What you are describing is a cgi script. It doesn't have to produce any output to the user.

    It is far and away the easiest way to trigger the server processing something at the click of a link. Why don't you want to use it?
  12. #7
  13. Hello World :)
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2003
    Location
    Hull, UK
    Posts
    2,537
    Rep Power
    69
    Like Sfb said any server-side process requires nothing from the users end except that he or she exists and what your describing sounds like CGI to me, unless you have client-side and server-side mixed up.

    In which case you want an executable (say from py2exe or similar - which would the server to run on windows... if you use p2exe) to run on your server without Python being installed?

    Mark.
    programming language development: www.netytan.com Hula

  14. #8
  15. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2003
    Location
    Canada
    Posts
    185
    Rep Power
    0
    i guess the question is like this: suppose i create a tic tac toe game in python. and i want to put it on my website so others can play the game. it is not a cgi script. as if they had it on their computer. since i'm using python already for cgi scripting can't the program excute and have the user play the game. i just want to use python to create dynamic webpages. like javascript, and i'm thinking the user does not need to have it installed since my server has it installed already. is this not possible. or is this something where the browser HAS to support python.
    thank you all for your time in answering.
    "In theory, there is no difference between theory and practice.
    But, in practice, there is."

  16. #9
  17. Hello World :)
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2003
    Location
    Hull, UK
    Posts
    2,537
    Rep Power
    69
    Now i'm hearing the applet, i might be wrong but when you talk about games i imagin GUI - in which case this is only possable with Grail (a browser writen in Python which is no longer being activly developed) or using Jython...

    If you want to use Python like Javascript then yes this is possable but you need to have Python installed on the clients computer. And i believe you also need the win32all module to do this on windows. Yet to hear of anything like this on *nix though

    Mark.
    programming language development: www.netytan.com Hula

  18. #10
  19. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2003
    Posts
    38
    Rep Power
    12
    Maybe you should consider using mod-python?? No need to have python running on the client side.

    Then you can access all your python code from a webpage using forms, links, etc.
  20. #11
  21. Hello World :)
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2003
    Location
    Hull, UK
    Posts
    2,537
    Rep Power
    69
    mod_python just provides another way to handle Python on the web although it does still provides a CGI handler if you're not comfortable with the default publisher handler.

    I guess we've got a little comfused about what we want to do here but CGI or mod_python should t the job in most cases. The problem arises when you have to have an interactive GUI (an applet) or want to effect the browser in a similar way which Javascript does (in which case we're talking Client-Side).

    Still waiting for PSP to become stable and supported - thats gonna be great!

    Mark.
    programming language development: www.netytan.com Hula


IMN logo majestic logo threadwatch logo seochat tools logo