mercredi 1 février 2017

Python: Web Module hosting local web server?

I have the following piece of Python code:

import web
import json
import getpass

username = getpass.getuser()

class index:
    def GET(self):
        data = {
            "username": username
        }
        web.header("Content-Type", "application/json")
        return json.dumps(data)

How could I make this piece of code host a web server on the local client machine, so I could get the users username from a web application that makes calls to the local clients IP address: 127.0.0.1 on port 80 - 127.0.0.1:80, or is there are better/easier way to do this. I've also tried using Python's SimpleHTTPServer but can't seem to output JSON, any ideas?




Aucun commentaire:

Enregistrer un commentaire