Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
cgi script help
#1
i follow the python guide to write a html and cgi script as follow in pyCharm on a macbook,however,i got 404 error after i click submit

the html
Output:
<html> <title>Interactive Page</title> <body> <form method=POST action="cgi-bin/cgi101.py"> <P><B>Enter your name:</B> <P><input type=text name=user> <P><input type=submit> </form> </body></html>
the cgi script
#!/usr/bin/python
import cgi
form = cgi.FieldStorage()
print('Content-type: text/html\n')
print('<title>Reply Page</title>')
if not 'user' in form:
    print('<h1>Who are you?</h1>')
else:
    print('<h1>Hello <i>%s,</i>!</h1>' % cgi.escape(form['user'].value))
Reply
#2
Could you please share the tutorial link?

What are the permissions for cgi-bin/cgi101.py?
Test it with chmod 755 cgi101.py.
Reply
#3
i used pycharm to write the script
so the cgi101.html and cgi101.py are locate in my macbook /Users/xxxxx/PycharmProjects/python/python_program_1/CGI
tried chmod 755 cgi101.py,still got the 404 error
Reply
#4
Which Web Server are you using?
It must support CGI and you'll have to put all the files in its folder (/var/www ?).
Reply
#5
(Jul-16-2018, 10:34 AM)gontajones Wrote: var
no,i put it in /Library/Webserver/GCI-Executables
i follow this link to write a new script
but the when i open
[url=http://localhost/cgi-bin/test.py]http://localhost/cgi-bin/test.py

,it gives the text,not the result of python script.
so why the script does not run?
if this issue can be solved,i think i can solve my original.
Reply
#6
Ok, lets investigate the error following this last tutorial.

Post the output of these commands:
1 - ls -la /Library/Webserver/GCI-Executables
2 - ls -la /var/log/apache2
2.1 - cat /var/log/apache2/error_log
Reply
#7
Output:
ls -la /Library/WebServer/CGI-Executables/
Output:
drwxr-xr-x 5 root wheel 170 Jul 16 22:14 . drwxr-xr-x 5 root wheel 170 Jul 15 22:56 .. -rw-r--r-- 1 root wheel 1074 Dec 17 2012 printenv.vbs -rw-r--r-- 1 root wheel 1133 Dec 17 2012 printenv.wsf -rwxr-xr-x@ 1 xiayao staff 160 Jul 16 22:03 test.py
Output:
ls -la /var/log/apache2
Output:
drwxr-xr-x 4 root wheel 136 Jul 15 22:52 . drwxr-xr-x 72 root wheel 2448 Jul 17 21:45 .. -rw-r--r-- 1 root wheel 2287 Jul 17 13:40 access_log -rw-r--r-- 1 root wheel 1015 Jul 16 08:19 error_log
Output:
cat /var/log/apache2/error_log
Output:
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using 192.168.1.220. Set the 'ServerName' directive globally to suppress this message [Sun Jul 15 22:52:09.268721 2018] [mpm_prefork:notice] [pid 37486] AH00163: Apache/2.4.28 (Unix) configured -- resuming normal operations [Sun Jul 15 22:52:09.269014 2018] [core:notice] [pid 37486] AH00094: Command line: '/usr/sbin/httpd -D FOREGROUND' [Sun Jul 15 23:03:45.282062 2018] [mpm_prefork:notice] [pid 37486] AH00169: caught SIGTERM, shutting down AH00557: httpd: apr_sockaddr_info_get() failed for my-macbook AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1. Set the 'ServerName' directive globally to suppress this message [Mon Jul 16 08:19:25.383625 2018] [mpm_prefork:notice] [pid 112] AH00163: Apache/2.4.28 (Unix) configured -- resuming normal operations [Mon Jul 16 08:19:25.383908 2018] [core:notice] [pid 112] AH00094: Command line: '/usr/sbin/httpd -D FOREGROUND'
Reply
#8
It seems to be something with the apache.
Lets see some more info:

3 - cat /var/log/apache2/access
4 - cat /etc/apache2/httpd.conf
5 - ls -la /etc/apache2/users/

If there is a user config file in 5, post its content too.
5.1 - ls -la /etc/apache2/users/some_user.config

Did you restart the apache server?

sudo apachectl restart
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020