When posting code samples, use the [php], [html] or [code] tags as appropriate. They will separate the code from the rest of the post and preserve indenting, which is extremely important in Python.
You don't need two shebang lines. The second will do nothing. The "#!/usr/bin/env python" is probably more portable, so use that one.

Originally Posted by
bryanda
There's nothing in the script you posted that calls function hi.
Code:
#!/usr/bin/env python
print "Content-type: text/plain\n\n"
def hi():
print "hello"
hi()
Note that in Python 3, print is no longer a statement and you need to call it as a function, thusly: 'print("hello")'.
Python doesn't have native support for URIs; there's no connection between the URI and the Python code. If you want to call a function based on the URI, you'll have to explicitly handle the URI.
say.py:
Code:
#!/usr/bin/env python
import cgi, cgitb, os, re
#cgitb.enable()
print("Content-Type: text/plain\n")
def hi():
print("hello")
def bye():
print("goodbye")
actions={
'hi': lambda: hi(),
'bye': lambda: bye()
}
def dispatch(path_info):
matches=re.search('^/?([^/]+)', path_info or '/hi')
action=matches.group(1)
try:
actions[action]()
except KeyError:
print "Illegal action:", action
dispatch(os.environ.get('PATH_INFO'))
And here's a version that can handle query string parameters. Try open the page as "/cgi-bin/say2.py/bye" and "/cgi-bin/say2.py/bye?name=Dinsdale"
say2.py:
Code:
#!/usr/bin/env python
import cgi, os, re
print("Content-Type: text/plain\n")
def hi(name=None):
if name:
print 'hello,', name
else:
print "hello"
def bye(name=None):
if name:
print 'hello,', name
else:
print "hello"
actions={
'hi': lambda kwargs: hi(**kwargs),
'bye': lambda kwargs: bye(**kwargs)
}
def dispatch(path_info):
matches=re.search('^/?([^/]+)', path_info or '/hi')
action=matches.group(1)
try:
form=cgi.FieldStorage()
actions[action](dict([(k,form[k].value) for k in form]))
except KeyError:
print("Illegal action:", action)
dispatch(os.environ.get('PATH_INFO'))

Originally Posted by
bryanda
but there is error and i think is the "mod_python" not found. How should i install the mod_python and if needed how should i create a support ticket?
The X10 servers don't use mod_python and you can't install it. You could open a support ticket to request it, but mod_python is not necessary.