help

Python

Python is an incredibly fast (in execution terms) and efficient programming language. It can be used on the webspace service as long as your file ends in the file extension .py and the following is the first line of your script:

#!/usr/local/bin/python

Python version 2.2.1 is installed on the platform. If desired, you can also use the older version [v 2.1.1] of Python by using this as the first line of your script instead:

#!/usr/local/bin/python2.1

For more information about Python as a programming language, and how to write Python scripts, refer to the Python Language Website.

Where do I find the system programs I want to use?

There is a page on this helpsite that explains the location of the various programs that you may wish to call from your script. See here for more information.

back to top

Which modules are installed?

The full list of Python modules for the current version is available from the Python website, and the vast majority of these modules are installed on the platform (in fact, at time of writing, all of them). As stated previously, any module that needs to open a network connection will not work for security reasons.

back to top

Problems with getting scripts working

Like all other programming languages, Python is not supported by Virgin Media. This means that, while the languages should work fine, we don't assist you in your coding and will only be able to help you out if your site's config does not work (see below).

If you have any issues with getting your Python script to work, you should do the following:

  1. Examine the error logs for your site. If you login via FTP and look in the logs/today directory (you will need to go "up" one directory from the one that FTP puts you in when you login), you can access your CGI logs. You can also see them in a browser by logging into self care.
  2. Check the permissions of your script. In 90%+ of cases, scripts fail [giving a 500 Internal Server Error] because the script does not have permissions to execute. Most FTP programs now give you the option to set your permissions. CGI scripts should be set to permissions of 755.
  3. Debug your code. Download one of the many code debuggers you can get on the web. Start with the URL above and look for Python resources.
  4. Get onto the newsgroups. Rename your script to be a .txt file and put it in your site's root directory [the directory that FTP puts you in when you login]. Post a link to this file in blueyonder.discussion.pwp if you want help from fellow BY users. The best place to start, however, is the external newsgroup comp.lang.python

back to top

How do I know if the site is broken?

It is possible (however unlikely) that your site isn't working for some reason. To identify whether this is the case, you should do the following:

  1. Download the test Python script test-python.py from here (you can also see the source code here)
  2. Upload the file to your site
  3. Set the permissions to 755 via your FTP client
  4. Browse to the file in a browser

If you get the results of the script's execution in a browser (See a working example) it will helpfully tell you, after a short delay, what language it was written in!:

Hello. I'm a Python script
Hello. I'm a Python script

Then your site is working fine. There will be an issue with your code itself. See the section above as to what to do about this when it happens.

If you still get a failure, please report this in the support newsgroup blueyonder.discussion.pwp or contact us.

back to top

Do Python scripts have to be placed in a cgi-bin directory?

No. If you wish to put your scripts anywhere in your htdocs/ document root, you can feel free. It is, however, convention to keep them in one place.

back to top

What restrictions are there on Python?

We have disabled some functionality for security reasons. These include any script attempting to open network socket connections. These will not work.

All CGIs are sandboxed and chrooted. Sandboxing is the restriction of CPU usage that any one CGI script can utilise. If somebody writes a bad script, it can only get so big and then will stop growing. This is a protection measure to ensure the service is not affected by others. Chrooting is what the name suggests - Change Root. CGI scripts only have access to the necessary programs they have to on the server to be able to function as they cannot get to the system directories or files because as far as they are concerned the root of the server is your own personal webspace area.

The only other restrictions on CGIs are the standard acceptable usage restrictions as per the Virgin Media Acceptable Use Policy.

back to top

01-04-2009