0

This is a duplicate question of this, however none of the answers there worked for me. I have done a lot of research into this and am completely stumped.

I am running a super simple python script called /var/www/cgi/test.py:

#!/usr/bin/python3
# -*- coding: UTF-8 -*-
import cgitb


print('Content-Type: text/html; charset=utf-8\n')
print("Hello world")

However when I attempt to access this through my server at: https://server.com/cgi/test.py I get the following message:

enter image description here

This obviously doesn't tell me much, so I checked the /var/log/apache2/error.log file and found the following:

[Tue Jan 25 11:55:10.622681 2022] [cgi:error] [pid 29052] [client REDACTED] AH01215: (8)Exec format error: exec of '/var/www/cgi/test.py' failed: /var/www/cgi/test.py
[Tue Jan 25 11:55:10.623144 2022] [cgi:error] [pid 29052] [client REDACTED] End of script output before headers: test.py

Following my research online, I have tried and done the following:

  • I have added the necessary configuration lines into the apache config file at /etc/apache2/apache2.conf. It looks like the following (I initially just had the ScriptAlias as I'm fairly certain that's all that's needed but it wasn't working so I added the <Directory> config too:
#   work with the default configuration.

ScriptAlias /cgi/ /var/www/cgi/


<Directory "/var/www/cgi">
    Options +ExecCGI
    AddHandler cgi-script .cgi .py
</Directory>


# Global configuration
#
"/etc/apache2/apache2.conf" 235L, 7355C 
  • Restarted apache using sudo service apache2 restart since changing the config file
  • Changed the permissions of test.py to be chmod 777 test.py (overkill I know, but just in case)
  • Ensured the shebang is correct with which python3 returning /usr/bin/python3
  • I symlinked my crunchworld.conf as described in this post

Perhaps even more I'm forgetting. I'm truly at a loss, I feel like I've exhausted every avenue.

Does anyone have any idea why this error is still occurring?

Recessive
  • 1,780
  • 2
  • 14
  • 37

1 Answers1

0

Change the first line to

#!/usr/bin/env python3

from

#!/usr/bin/python3

Maybe this works?

Devang Sanghani
  • 731
  • 5
  • 14
  • It doesn't. I actually had it that way around the first time but thought having it the same as `which python3` would help clear up confusion – Recessive Jan 25 '22 at 12:36