Python script error when using print

R

Robbie

Hi all,

So, I'm trying to use Python with an apache2 server to create some web
pages. The web server is configured and seems to work correctly, but
only with a certain type of script.

For instance, this script works fine

#!/usr/bin/env python
def index():
s = "Hello World"
return s

But, a script like this, does not.
#!/usr/bin/env python
print "hello world"

When I try to use the script with print, the server returns a broken
link error. There is nothing in the apache error log to help me
understand why it won't work.

Any help?

thanks

robbie
 
A

Albert W. Hopkins

Hi all,

So, I'm trying to use Python with an apache2 server to create some web
pages. The web server is configured and seems to work correctly, but
only with a certain type of script.

For instance, this script works fine

#!/usr/bin/env python
def index():
s = "Hello World"
return s

But, a script like this, does not.
#!/usr/bin/env python
print "hello world"

When I try to use the script with print, the server returns a broken
link error. There is nothing in the apache error log to help me
understand why it won't work.

Is this a CGI script? You need to return headers (like Content-type):

e.g. (untested)

print "Content-type: text/plain"
print
print "hello world"

See also
http://docs.python.org/library/cgi.html

-a
 
P

Pierre Quentel

Is this a CGI script?  You need to return headers (like Content-type):

e.g. (untested)

print "Content-type: text/plain"
print
print "hello world"

See alsohttp://docs.python.org/library/cgi.html

-a

Hi,

Are you trying to use some Python web framework behind Apache ? (as
suggested by the fact that your first script "runs", i.e. probably
prints "Hello World"). In this case the "not found" error in the
second script would mean that the framework requires a function in the
script

- Pierre
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,175
Messages
2,570,942
Members
47,491
Latest member
mohitk

Latest Threads

Top