1

I am getting this error:

Server error!

The server encountered an internal error and was unable to complete your request.

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

If you think this is a server error, please contact the webmaster.

Error 500

192.168.64.2 Apache/2.4.41 (Unix) OpenSSL/1.1.1d PHP/7.4.1 mod_perl/2.0.8-dev Perl/v5.16.3*

I have added .py to the addhandler AddHandler cgi-script .cgi .pl .py ScriptInterpreterSource Registry-Strict

I also have pip and pymysql installed and am using python 3.8.

I have also have the permissions set to chmod 755 sudo chmod 755

have also tried chmod 755, +x but no luck I have also checked the error logs but no clear problem

btw I am using Mac

Heres my code:

#!/usr/bin/local/env python3
print ('Content-type: text/html\r\n')
print ('\r\n')
print ()
print ('<html>')
print ('<head>')
print ('</head>')
print ('<body>')
print ('Hello Python')
print ('</body>')
print ('</html>')
Pal Dhillon
  • 93
  • 10
  • Can you share the relevant lines from the error.log file Apache2 writes errors to? –  May 26 '20 at 02:06
  • `End of script output before headers: python.py` – Pal Dhillon May 27 '20 at 02:12
  • 1
    Try making the first line go directly to you Python file. Also, this probably has nothing to do with your error, but you're going to want to change `Content-type: text/html\n\n` to end in `\r\n`: `Content-type: text/html\r\n`. See https://stackoverflow.com/questions/5757290/http-header-line-break-style – hostingutilities.com May 27 '20 at 03:13
  • Thanks for sharing the log line. Assuming `python.py` is placed in the correct directory, maybe just try restarting XAMPP (see this answer https://stackoverflow.com/a/45476400/11553043)? –  May 27 '20 at 13:22
  • It doesn't work and I am using Mac – Pal Dhillon May 28 '20 at 01:44
  • @wp-overwatch.com is the location supposed to be like this at the top: #!c:/Library/Frameworks/Python.framework/Versions/3.8/bin/python3 – Pal Dhillon May 28 '20 at 02:01
  • Macs never start filepaths with C:/. On the terminal type in `which python3`, and use that filepath (with the `#!` in front of it). – hostingutilities.com May 28 '20 at 03:56
  • @wp-overwatch.com it still doesn't affect anything – Pal Dhillon May 29 '20 at 01:43
  • Take a look at https://httpd.apache.org/docs/2.4/howto/cgi.html and make sure you've set everything up correctly. Beyond that, I don't know what to do. – hostingutilities.com May 29 '20 at 16:51
  • `print("Content-Type: html \r\n")` return me a blank page. I am trying to load a simple `html` page – Moeez Mar 21 '22 at 11:21

0 Answers0