XAMPP cannot run python script

Viewed 1364

I am trying to run python code on XAMPP on my MAC system. I have followed this link.

Now when I run php code then its runs successfully but when I try to run my .py file then gives me following error:-

Server error!

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

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

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

Error 500

localhost Apache/2.4.25 (Unix) OpenSSL/1.0.2l PHP/7.1.6 mod_perl/2.0.8-dev Perl/v5.16.3

-> I have made the changes to httpd.conf : AddHandler cgi-script .cgi .pl .py
-> Python version : Python 2.7.10

I have my .php and .py file in htdocs folder, but lot of post suggest that the .py file should be in cgi-bin folder. [cgi-bin folder is write protected, not able to put files there]

Please help. Thank you

1 Answers

I had a similar error on my XAMPP server and I was able to fix the error by putting shebang in my python file like this #!/usr/bin/python/python.exe and putting print statement after it print ("Content-Type: text/plain;charset=utf-8\n).

These two lines will be on top of your python file. You can find where is your python installed by going to CMD and type where python, which will show you the path to python, that is your shebang: '#!whereever your python is installed' for linux you would use terminal and whereis command. FYI my python file was in htdoc folder. You can test your file in browser and it should work

Related