Nif,
I copied your kml script and it worked fine for me, once I changed
the line endings to Unix Line Endings. (Before I did that I would get
a "permature end of script headers error" in my apache logs and the
server would repond with a "500 Internal Server Error"). Are you
perhaps writing and uploading this script from windows? If so, and you
are running the script on an apache linux server then you'll have to
be careful about line endings.
I put it in my cgi bin, calling it nif.py Then opened a terminal
window and typed:
chmod +x nif.py
This makes it able to be executed as a program.
Then I opened the file in a text editor and converted the line
endings to Unix.
Then I went to
http://localhost/cgi-bin/nif.py and the server
responded by downloading the KML.
Make sure you get this step working before trying to link to the
python script from a network link.
Also, I modified the script slightly as below:
----
#!/usr/bin/python
import random
import cgi
latitude = random.randrange(-90, 90)
longitude = random.randrange(-180, 180)
kml = (
'''
<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="
http://earth.google.com/kml/2.2">
<Placemark>
<name>Random Placemark</name>
<Point>
<coordinates>%d,%d</coordinates>
</Point>
</Placemark>
</kml>
''') %(longitude, latitude)
print "Content-Type: application/vnd.google-earth.kml+xml"
print kml
----
which gives:
<Placemark>
<name>Random Placemark</name>
<Point>
<coordinates>129,-14</coordinates>
</Point>
</Placemark>
</kml>
Cheers,
Dane