I'm trying to use python cgi module with apache, but I'm getting "500 Internal Server Error ". I've configurated the server following those instructions. I tried running script with sudo python3 my_script.py and there is no any error.
getAllSubjects.py file:
#!/usr/bin/python3
print("Content-Type: text/html\n")
import cgi
from bot.puescBot import Session
fieldData = cgi.FieldStorage()
data = []
data.append(fieldData.getvalue('i1'))
data.append(fieldData.getvalue('i2'))
data.append(fieldData.getvalue('i3'))
data.append(fieldData.getvalue('i4'))
s = Session()
s.logIn()
puesc = s.collectSubjects(str(data[0]), str(data[1]), str(data[2]), str(data[3]))
if puesc['status'] == 0:
p = puesc['message']
content = f'<p>{p}</p>'
else:
p = puesc['data']
content = f'<p>{p}</p>'
print(f"""
<html>
<head>
<meta charset="UTF-8">
<title>PUESC BOT</title>
</head>
<body>
{content}
</body>
</html>
""")
index.html file:
<html>
<head>
<meta charset="UTF-8">
<title>PUESC BOT</title>
</head>
<body>
<form action="../cgi-bin/getAllSubjects.py" method="get" id="form">
<p>NIP:
<input type="text" name="i1"/>
</p>
<p>EORI:
<input type="text" name="i2"/>
</p>
<p>Nazwa skrócona:
<input type="text" name="i3"/>
</p>
<p>Nazwa pełna:
<input type="text" name="i4"/>
</p>
<input type="submit" value="Opłać i wyszukaj"/>
</form>
</body>
</html>
Full error from apache2/error.log:
[Tue Mar 22 19:39:30.837790 2022] [cgid:error] [pid 1649:tid 3069833024] (2)No such file or directory: AH01241: exec of '/var/www/cgi-bin/getAllSubjects.py' failed
[Tue Mar 22 19:39:30.842430 2022] [cgid:error] [pid 826:tid 2852025344] [client 192.168.1.13:53964] End of script output before headers: getAllSubjects.py, referer: http://192.168.1.30/