I know this is a fairly common question but I've left no digital stone unturned and still can't find an answer that works for me.
I am running MAMP and Pythons 2.x and 3.x on a Mac running macOS Sierra. I am trying to learn Python CGI scripting and I am going through this tutorial.
So far, I am at the point where I test CGI (here). I've uploaded my file to the server with the name index.cgi, in /Applications/MAMP/cgi-bin/index.cgi. However, when navigating to http://localhost/cgi-bin/index.cgi I get 500 - Internal Server Error. This occurs regardless of whether I save as a .cgi or .py.
Here's what I've tried:
- Consulting the Apache docs
- Checking file permissions
- Adjusting the
Content-Type - Ensuring my file is in UNIX format
Checking the Apache error log (
Applications/MAMP/logs/apache_error.log)Note: I have also tried clearing them and then reloading to isolate the individual error - it doesn't help. All I get is
[TIMESTAMP] [error] [client ::1] Premature end of script headers: index.py
Here's the code in index.py/index.cgi:
#!/usr/bin/env python
# -*- coding: UTF-8 -*-
# enable debugging
import cgitb
cgitb.enable()
print("Content-Type: text/plain;charset=utf-8")
print()
print("Hello World!")
Any help would be hugely appreciated!