from wsgiref.simple_server import * def aaa(environ,start_response): # try: # request_body_size = int(environ.get('CONTENT_LENGTH', 0)) # except (ValueError): # request_body_size = 0 # request_body = environ['wsgi.input'].read(request_body_size) # print request_body+"#" start_response("200 OK",[('content-type',"text/html")]) return ['aaaa'] if __name__ == '__main__': httpd = make_server('', 80, aaa,WSGIServer,WSGIRequestHandler) sa = httpd.socket.getsockname() print 'http://{0}:{1}/'.format(*sa) # Respond to requests until process is killed httpd.serve_forever()
原因在于
C:\Python27\Lib\BaseHTTPServer.py
def address_string(self): host, port = self.client_address[:2] return socket.getfqdn(host)#very slow here
print socket.getfqdn("192.168.1.101")#这里要用10秒左右
解决:
修改C:\Python27\Lib\wsgiref\simple_server.py
host = self.address_string()#very slow here 改为 host = ""