+
Skip to content

Minimal Python server that takes a JSON input and returns a JSON. Useful to create a communication interface of a Python application with applications in other platforms and languages.

License

Notifications You must be signed in to change notification settings

hviana/python_server

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 

Repository files navigation

python_server

Minimal Python server that takes a JSON input and returns a JSON. Useful to create a communication interface of a Python application with applications in other platforms and languages.

Code

from http.server import HTTPServer, BaseHTTPRequestHandler
import json
import time

port = 41425

class JSONHandler(BaseHTTPRequestHandler):
    def do_POST(self):
        input_string = self.rfile.read(int(self.headers.get('content-length')))
        input_obj = json.loads(input_string);
        print('JSON received: '+str(input_obj));

        output_obj = { "time": time.time() }; #example output object
        print('Sending data as JSON : '+str(output_obj));

        self.send_response(200)
        self.send_header('Content-Type', 'application/json; charset=utf-8')
        self.end_headers()
        self.wfile.write(json.dumps(output_obj).encode('utf-8'))
        return
server_object = HTTPServer(server_address=('', port), RequestHandlerClass=JSONHandler)
print('starting server at port: '+str(port))
server_object.serve_forever()

About

Minimal Python server that takes a JSON input and returns a JSON. Useful to create a communication interface of a Python application with applications in other platforms and languages.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载