urllib.urlopen never end up in an HTTPRequestHandler

Bertrand Geston bergeston at yahoo.fr
Thu Apr 11 11:26:17 EDT 2002


I set my box as a proxy on IE (port 8001), I launch the script below from
the command line (dos box  under w2k) and I never reach the "print 'ready to
read' ..." line.
On the other hand, if I try to do "urllib.urlopen" in the interactive window
of PythonWin, it works perfectly well (with the same URL obviously).
Any explanation ?
TIA for any hint.
B.

----ProxyHTTPServer.py------------------------------------------------------
----------------------------------------------------------------------------
------------------------
import BaseHTTPServer, SimpleHTTPServer, urllib

class ProxyHTTPRequestHandler(SimpleHTTPServer.SimpleHTTPRequestHandler):

    def handle(self):
        SimpleHTTPServer.SimpleHTTPRequestHandler.handle(self)
        print '*********************\n Command: %s\n Path: %s\n Request
version: %s\n' % (self.command, self.path, self.request_version)

    def do_GET(self):
        """Serve a GET request."""
        print 'ready to open', self.path
        distant_file = urllib.urlopen(self.path)
        print 'ready to read', self.path
        content = distant_file.read()
        print 'ready to send back', self.path
        self.wfile.write(content)
        print 'everything done with', self.path

    def do_HEAD(self):
        print 'unexpected de_HEAD request'

def run(server_class=BaseHTTPServer.HTTPServer, handler_class =
ProxyHTTPRequestHandler):
    server_address = ('', 8001)
    httpd = server_class(server_address, handler_class)
    httpd.serve_forever()

if __name__ == '__main__':
    run()







More information about the Python-list mailing list