Check interpreter is addedd to script, add either #!/usr/bin/python
or #!/usr/bin/env python
Check logs at /var/log/apache2
for detailed errors, if any.
i found missing pip packages in the log.
ubuntu@ip:/var/log/apache2$ ll
total 36
drwxr-x--- 2 root adm 4096 Nov 6 18:08 ./
drwxrwxr-x 12 root syslog 4096 Nov 6 18:57 ../
-rw-r----- 1 root adm 9543 Nov 6 21:36 access.log
-rw-r----- 1 root adm 15941 Nov 6 21:35 error.log
-rw-r----- 1 root adm 0 Nov 6 18:08 other_vhosts_access.log
ubuntu@ip:/var/log/apache2$
Access the script, example tail -f http://<ip>/cgi-bin/test-db.py
[Sun Nov 06 21:35:18.928560 2022] [cgi:error] [pid 8303:tid 139738648380992] [client 49.207.201.90:5556] AH01215: Traceback (most recent call last):: /usr/lib/cgi-bin/test-db.py
[Sun Nov 06 21:35:18.928839 2022] [cgi:error] [pid 8303:tid 139738648380992] [client 49.207.201.90:5556] AH01215: File "/usr/lib/cgi-bin/test-db.py", line 3, in <module>: /usr/lib/cgi-bin/test-db.py
[Sun Nov 06 21:35:18.929051 2022] [cgi:error] [pid 8303:tid 139738648380992] [client 49.207.201.90:5556] AH01215: import pymysql: /usr/lib/cgi-bin/test-db.py
[Sun Nov 06 21:35:18.929213 2022] [cgi:error] [pid 8303:tid 139738648380992] [client 49.207.201.90:5556] AH01215: ModuleNotFoundError: No module named 'pymysql': /usr/lib/cgi-bin/test-db.py
[Sun Nov 06 21:35:18.941377 2022] [cgi:error] [pid 8303:tid 139738648380992] [client 49.207.201.90:5556] End of script output before headers: test-db.py