NicholasTao / NicholasTao.github.io

✨ Build a beautiful and simple website in literally minutes. Demo at https://beautifuljekyll.com
https://beautifuljekyll.com
MIT License
0 stars 0 forks source link

webob #7

Open NicholasTao opened 2 years ago

NicholasTao commented 2 years ago

!/usr/bin/python

"""WSGI server example""" from future import print_function

import sys

import webob from webob import Request, Response from gevent import monkey monkey.patch_all() from gevent.pywsgi import WSGIServer

def application(env, start_response): a = Request(env) for k,v in env.items(): print(k, v) print("=====", a.json, type(a.json)) if env['PATH_INFO'] == '/':

start_response('200 OK', [('Content-Type', 'application/json')])

    res = Response(status=200, json_body={"3": 2})
    return res(env, start_response)
    # return [b"<b>hello world</b>"]

start_response('404 Not Found', [('Content-Type', 'text/html')])
return [b'<h1>Not Found</h1>']

if name == 'main': print(sys.version) print('Serving on 8088...') WSGIServer(('127.0.0.1', 8088), application).serve_forever()