1

I'm creating a simple server to serve a form via Python. The user will post their name and a message through an HTML form, on the server-side python will retrieve these values and append them to a file. I've tested each part on their own, other then the cgi.fieldstorage. When running the code, it returns no errors but will not display my HTML page. Any suggestions?

The Python file is below

#!/usr/bin/python

import sys
import os
import SimpleHTTPServer
import cgi
import SocketServer


class MyHandler(SimpleHTTPServer.SimpleHTTPRequestHandler):
    def do_GET(self):
        form = cgi.FieldStorage()
        user = form.getvalue("name")
        message = form.getvalue("line") 

        #Append to data.txt
        data = open('data.txt', 'a')    #open this txt file to then append to it
        data.write('%s: %s\n'% (user, message)) #Append this line to the file
        data.close()

if __name__=="__main__":    
    PORT = 9020                         #declare which port to serve on.
    server = SocketServer.TCPServer(('',PORT),MyHandler) #call the class to   generate the server
    print "Serving on port: ", PORT     #Print what port the Server is serving on
    server.serve_forever()              #Loop serving requests
  • I'd find an example for SimpleHTTPRequestHandler that returns a simple "hello world" string and compare it to what you have & work it back until you find the issue that's blocking you – Jason De Arte Mar 26 '16 at 07:22

0 Answers0