How do I test Python to make sure it is working for my account?

The following will allow you to create a test script to ensure Python is working on your account and view the environment variables.

  1. Create a python file locally on your computer with the following code:
    #!/usr/bin/python
    print "Content-type: text/html"
    print
    print "<pre>"
    import os, sys
    from cgi import escape
    print "<strong>Python %s</strong>" % sys.version
    keys = os.environ.keys()
    keys.sort()
    for k in keys:
        print "%s\t%s" % (escape(k), escape(os.environ[k]))
    print "</pre>"
    
  2. Create or modify an existing .htaccess file, add the following lines:
    AddType text/html py
    AddHandler cgi-script .py
    
  3. Save the files and upload them both to your public_html folder via FTP or the cPanel File Manager.

  4. Set the permissions of your .py file to 755 so that the server can execute it, this can be done via the File Manager or in most FTP clients.

  5. Navigate to /index.py and you should see output of the environment variables and their values.
  • 116 Users Found This Useful
Was this answer helpful?

Related Articles

How do I parse PHP in HTML pages?

If you wish parse PHP in your HTML pages you need to add the following line you the .htaccess...

How do I use the Ioncube loaders?

The Ioncube loaders are installed and ready for use so you don't need to do anything to use them.

Is PHP ran as an Apache module or as CGI?

We run suPHP on our servers, so PHP is running as CGI.

Can I run PHP scripts anywhere on my web space?

You can run PHP scripts anywhere on your web space with the exception of the "cgi-bin".

General SSI Information

SSI (Server Side Include) tags allow you to include dynamic content in standard HTML pages. All...