How to start python BaseHttpserver in AWS EC2 ubuntu instance -
i've below httpserver code working fine on local ubuntu pc. when try run code in aws ec2 ubuntu vm, server doesn't start. how can achieve below functionality in ec2 ubuntu? help/info great
from basehttpserver import basehttprequesthandler import cgi import os import time class posthandler(basehttprequesthandler): def savefile(self,file_data, fname, dirname): directory = '/home/user/documents/ts/logs/' directory = directory + time.strftime("%y-%m-%d") if not os.path.exists(directory): os.makedirs(directory) localfname = directory+'/'+fname open(localfname,'wb') f: f.write(file_data) def do_post(self): # parse form data posted form = cgi.fieldstorage( fp=self.rfile, headers=self.headers, environ={'request_method':'post', 'content_type':self.headers['content-type'], }) # begin response self.send_response(200) self.end_headers() self.wfile.write('client: %s\n' % str(self.client_address)) self.wfile.write('user-agent: %s\n' % str(self.headers['user-agent'])) self.wfile.write('path: %s\n' % self.path) self.wfile.write('form data:\n') # echo information posted in form field in form.keys(): field_item = form[field] if field_item.filename: # field contains uploaded file fname = form['filename'].value dirname = form['dirname'].value file_data = field_item.file.read() self.savefile(file_data, fname, dirname) file_len = len(file_data) del file_data self.wfile.write('\tuploaded %s "%s" (%d bytes)\n' % \ (field, field_item.filename, file_len)) else: # regular form value self.wfile.write('\t%s=%s\n' % (field, form[field].value)) return if __name__ == '__main__': basehttpserver import httpserver server = httpserver(('locahost', 8080), posthandler)
Comments
Post a Comment