码迷,mamicode.com
首页 > 其他好文 > 详细

获取wsgi environ变量

时间:2015-09-11 18:56:03      阅读:195      评论:0      收藏:0      [点我收藏+]

标签:

server.py

from wsgiref.simple_server import make_server
from ex import application

httpd=make_server(‘‘,8000,application)
print Serving Http on port 8000
httpd.serve_forever()

ex.py

def application(environ,start_response):
    start_response(200 OK,[(Content-Type,text/html)])
    body=<ol>
    for key,value in environ.iteritems():
        body=‘‘.join([body,<li>%s:%s</li> %(key,value)])
    else:
        body=‘‘.join([body,</ol>])
    return [body]

两文件方式在同一目录下,python server.py 启动

浏览器 访问 http://localhots:8000

或者使用 

import urllib2
request=urllib2.urlopen(http://localhost:8000) 
response=request.read()

做get 请求

获取wsgi environ变量

标签:

原文地址:http://www.cnblogs.com/Citizen/p/4801547.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!