<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=Content-Type content="text/html; charset=iso-8859-1">
<META content="MSHTML 6.00.6001.18203" name=GENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=#ffffff>
<DIV><FONT face=Arial size=2>I have the DOS box with the message </FONT></DIV>
<DIV><FONT face=Arial size=2>Localhost CGI server started </FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2>But when i try this </FONT></DIV>
<DIV>
<P class=indent><EM>Back in the www directory, <!--l. 11015--></EM></P>
<P class=indent><EM></EM></P>
<OL class=enumerate1>
  <LI class=enumerate id=x1-126018x1><EM>Open the web link <SPAN 
  class=obeylines-h><A class=url href=""><SPAN 
  class=ec-lmtt-10>http://localhost:8080/adder.html</SPAN></A></SPAN> 
  (preferably in a new window, separate from this this tutorial). </EM></LI>
  <LI class=enumerate id=x1-126020x2><EM>You should see an adder form in your 
  browser again. Note that the web address no longer includes 'cs.luc.edu'. 
  Instead it starts with 'localhost:8080', to reference the local Python server 
  you started. Fill out the form and test it as before. </EM></LI>
  <LI class=enumerate id=x1-126022x3><EM>Look at the console window. You should 
  see a log of the activity with the server. <SPAN class=ec-lmri-10>Close 
  </SPAN>the server window. </EM></LI>
  <LI class=enumerate id=x1-126024x4><EM>Reload the web link <SPAN 
  class=obeylines-h><A class=url href=""><SPAN 
  class=ec-lmtt-10>http://localhost:8080/adder.html</SPAN></A></SPAN>. You 
  should get an error, since you refer to localhost, but you just stopped the 
  local server.</EM></LI></OL></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2>I get the </FONT><FONT face=Arial size=2>Windows 
Error </FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2>Failed to Connect</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2>  </FONT><FONT face=Arial size=2>The 
connection was refused when attempting to contact localhost:8080.</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=Arial size=2> </FONT><FONT face=Arial size=2> Though 
the site seems valid, the browser was unable to establish a connection.</DIV>
<DIV> </DIV>
<DIV> </DIV>
<DIV> </DIV>
<DIV><BR>    *  Could the site be temporarily unavailable? 
Try again later.</DIV>
<DIV> </DIV>
<DIV><BR>    *  Are you unable to browse other sites?  
Check the computer's network connection.</DIV>
<DIV> </DIV>
<DIV><BR>    *  Is your computer or network protected by a 
firewall or proxy? Incorrect settings can interfere with Web browsing.</DIV>
<DIV> </DIV>
<DIV> </DIV>
<DIV>The py file brings up the DOS box as if its running ok </DIV>
<DIV> </DIV>
<DIV> </DIV>
<DIV>'''Run a local cgi server from the current directory that treats *.cgi 
files<BR>as executable python cgi scripts.'''</DIV>
<DIV> </DIV>
<DIV>import http.server, sys, os</DIV>
<DIV> </DIV>
<DIV>class 
CGIExtHTTPRequestHandler(http.server.CGIHTTPRequestHandler):<BR>    
'''This request handler mimics the Loyola server, which looks for CGI 
files<BR>    to end in '.cgi' and be in any directory as opposed 
to the CGIHTTPServer<BR>    expectation that the cgi script are 
of the form /cgi-bin/*.py.'''<BR>    <BR>    def 
is_python(self, path):<BR>        """Test 
whether argument path is a Python script: allow 
.cgi"""<BR>        return 
path.lower().endswith('.cgi')</DIV>
<DIV> </DIV>
<DIV>    def 
is_cgi(self):<BR>        '''As on xenon, go 
by extension only.'''<BR>        base = 
self.path<BR>        query = 
''<BR>        i = 
base.find('?')<BR>        if i != 
-1:<BR>            query 
= base[i:]<BR>            
base = base[:i]<BR>        if not 
base.lower().endswith('.cgi'):<BR>            
return False<BR>        [parentDirs, script] 
= base.rsplit('/', 1)<BR>        
self.cgi_info = (parentDirs, 
script+query)<BR>        return 
True<BR>   </DIV>
<DIV> </DIV>
<DIV>def run_server():<BR>    dirName = 
os.getcwd()<BR>    blanks = dirName.count(' 
')<BR>    if 0 < blanks:  # server cannot handle blanks 
in path names<BR>        print("""The path to 
this directory contains {blanks} space(s):<BR>{dirName}<BR>Either rename 
directories to remove the blanks or<BR>move this directory to a place with no 
blanks in the path.<BR>Aborting the local server 
run!""".format(**locals()))<BR>        
input("Press return after reading this 
message.")<BR>        
return<BR>        <BR>    
server_addr = ('localhost', 8080)<BR>    cgiServer = 
http.server.HTTPServer(server_addr, 
CGIExtHTTPRequestHandler)<BR>    sys.stderr.write('Localhost CGI 
server started\n.')<BR>    cgiServer.serve_forever()</DIV>
<DIV> </DIV>
<DIV>run_server()<BR></DIV>
<DIV> </DIV>
<DIV><BR>        
<BR>        
<BR>      </DIV>
<DIV> </DIV>
<DIV><BR>      <BR>      
</FONT></DIV></BODY></HTML>