Sto cercando di creare un semplice server web Python per salvare il testo che è Post
ed in un file chiamato store.json
che si trova nella stessa cartella dello script python. Ecco metà del mio codice, qualcuno può dirmi quale dovrebbe essere il resto?Simple Python Webserver per salvare il file
import string,cgi,time
from os import curdir, sep
from BaseHTTPServer import BaseHTTPRequestHandler, HTTPServer
#import pri
class StoreHandler(BaseHTTPRequestHandler):
def do_GET(self):
try:
if self.path == "/store.json":
f = open(curdir + sep + "store.json") #self.path has /test.html
self.send_response(200)
self.send_header('Content-type','text/json')
self.end_headers()
self.wfile.write(f.read())
f.close()
return
return
except IOError:
self.send_error(404,'File Not Found: %s' % self.path)
def do_POST(self):
//if the url is 'store.json' then
//what do I do here?
def main():
try:
server = HTTPServer(('', 80), StoreHandler)
print 'started...'
server.serve_forever()
except KeyboardInterrupt:
print '^C received, shutting down server'
server.socket.close()
if __name__ == '__main__':
main()
Dice 'ImportError: nessun modulo chiamato 'BaseHTTerver'' –
Ok, è necessario cambiare' da BaseHTTerver' a 'da http.server' –
Spiacente, non abbiamo notato la parte' -3.x' del tag. – gvalkov