標籤:
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 = ""
解決Python(2.7)Webserver 區域網路內非本機訪問時速度極慢