1

My problem...

  1. We have a local network.
  2. i run a python basehttpserver on a virtual machine with Ubuntu Server(12.04.2).

When i open in browser link 192.168.101.3:8081/index.html, get request processed 10 seconds, why??

example basehttpserver

class ReqHandler( BaseHTTPServer.BaseHTTPRequestHandler):
    def __init__(self, request, client_address, server):
        BaseHTTPServer.BaseHTTPRequestHandler.__init__( self, request, client_address, server )

    def do_GET(self ):
        self.performReq(self.path.decode('utf-8'))  

    def performReq (self, req ):
        curDir = os.getcwd()
        """ Performing http request """
        if req == '/' :
            self.path = '/index.html'
        fname  = curDir + '/' + self.path[1:]   
        fname = unquote(fname).decode('utf8')
        try:
            self.send_response(200,"Ok!")
            self.send_header('Content', 'text/xml; charset=UTF-8' )
            self.end_headers()
            f = open(fname, 'rb')
            self.wfile.write(f.read())  
            f.close()
            print 'file '+fname+" Ok"   

        except IOError:
            print 'no file '+fname  
            self.send_error(404)

def run(server_class=BaseHTTPServer.HTTPServer):
    server_address = ('', 8081)
    server = server_class(server_address, ReqHandler)
    print('server ok!')
    server.serve_forever()

screenshot from server log server

IP machine with ubuntu server 192.168.101.3

Sorry for my English.

My solution - I added the following method in ReqHandler

def log_message(self,fmt, *args):
    print fmt%args
2
  • Profile your code with fabulous python "profile" library, that will tell you what and why: docs.python.org/2/library/profile.html Commented Oct 29, 2013 at 11:38
  • I am having the same issue with a basehttpserver on OSX. I am making a simple GET request to retrieve a single document from mongodb. The request stays delayed for around 10-20 seconds each time. The chrome console shows status "Waiting" during this time. Any other request like POST or PUT are completing in milliseconds. Also, GET requests to external sites are working as normal, so I definitely don't think the client is the issue. Please share if you find a solution and I'll do the same. Commented Dec 10, 2013 at 6:21

1 Answer 1

3

If your testing your webapp on a local network not connected to Internet, you may encounter these delays. It is because BaseHTTPServer is performing by default a lookup on the client IP (for logging purpose). Check this hack: http://bugs.python.org/issue6085

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.