天天看點

python wsgi 接口hello,%s ! hello,talen ! hello,max !

html wsgi web server

點選(此處)折疊或打開

  1. #!/usr/bin/env python3
  2. #-*- coding:utf-8 -*-
  3. '''
  4. def application(environ,start_response):
  5.     start_response('200 ok',[('Content-Type', 'text/html')])
  6.     body='

    hello,%s !

    ' % (environ['PATH_INFO'][1:] or 'web')
  7.     return [body.encode('utf-8')]

點選(此處)折疊或打開

  1. from wsgiref.simple_server import make_server
  2. from wsgi_client import application
  3. httpd=make_server('', 10086,application)
  4. print('Serving HTTP on port 10086')
  5. httpd.serve_forever()

t@localhost untitled$ python3 wsgi_server.py 

Serving HTTP on port 10086

127.0.0.1 - - [10/May/2016 14:28:21] "GET /talen HTTP/1.1" 200 22

127.0.0.1 - - [10/May/2016 14:28:27] "GET /max HTTP/1.1" 200 20

127.0.0.1 - - [10/May/2016 14:29:22] "GET /china HTTP/1.1" 200 22

127.0.0.1 - - [10/May/2016 14:29:22] "GET /favicon.ico HTTP/1.1" 200 28

127.0.0.1 - - [10/May/2016 14:29:34] "GET /US HTTP/1.1" 200 19

127.0.0.1 - - [10/May/2016 14:29:35] "GET /favicon.ico HTTP/1.1" 200 28

t@localhost untitled$ netstat -lntp |grep 10086

(Not all processes could be identified, non-owned process info

 will not be shown, you would have to be root to see it all.)

tcp        0      0 0.0.0.0:10086           0.0.0.0:*               LISTEN      4397/python3        

t@localhost untitled$ curl http://localhost:10086/talen

hello,talen !

t@localhost untitled$ curl http://localhost:10086/max

hello,max !

python wsgi 接口hello,%s ! hello,talen ! hello,max !
python wsgi 接口hello,%s ! hello,talen ! hello,max !