0
votes

I googled this and tried everything but I could not run my test.py on apache. I have updated httpd.conf file to AddHandler .py

#!/usr/local/opt/python/bin/python3.7

print("Hello World!")

When I open this file in browser I am getting this error

Error message: End of script output before headers: test.py

1

1 Answers

0
votes

Have you tried to use Flask instead? It start a server that you can access via browser.
Here you can find an Hello world tutorial, or also here.
First, you have to install Flask: pip install Flask.
Then the server code, saved in a python file, for example your_server.py, has to look like this:

from flask import Flask
app = Flask(__name__)

@app.route("/")
def hello():
return "Hello World!"

if __name__ == "__main__":
app.run()

You can run the script, then go to http://localhost:5000/ and you'll see the 'Hello World!' message.
Now you can modify the method hello() to do what you need, or create other method/operations. The tutorial can give you more details, but this is the main concept.