Last Problem, I Think, In CGI Script: Please Help

Ben Ocean zope at thewebsons.com
Thu May 3 22:50:52 EDT 2001


Sorry I'm not clear but don't worry: after working on it for an hour and 
walking away, I realized my dumb mistake. Thanks,
BenO

At 10:51 PM 5/3/2001 -0400, you wrote:
>not very clear what u are asking
>but i know to print the content in a file
>you need to use file.read() to read the contents
>so print file wouldn't work
>
>Ben Ocean wrote:
>
>>Hi;
>>I frame around a Web page from Kelley Blue Book on my car dealer's site. 
>>KBB has the visitor fill out a form. The data is then posted back to my 
>>car dealer's site via STDIN. I capture the data via cgi.FieldStorage(). I 
>>test to see if a certain variable of my own making is valid. If it is 
>>not, I raise a NameError exception and print to screen the data the 
>>visitor filled out in the form. Then I offer the visitor the opportunity 
>>to have this data sent back to the dealership or, conversely, printed to 
>>screen in a printer-friendly format. I do this by writing the data to a 
>>separate file at the same time as I originally post the data to the 
>>screen. The problem comes in when I try and retrieve the data from the 
>>file. When the visitor selects one of the aforementioned options, the 
>>variable of my own making for which I test (which the first time around 
>>threw the NameError exception) is set in STDIN in the URL and the same 
>>script is called. The page is printed to screen and the data is supposed 
>>to be read from the file I'd written, but for some reason it isn't! The 
>>data's in there, so what gives? Here's the part that's not working:
>>  >>>
>>    file = open("outfile.txt", "r")
>>    print file
>><<<
>>Should work, right? Your help is appreciated. The entire file follows if 
>>you care to look for errors, although I've tested the rest and it appears 
>>to be in good, working order.
>>TIA,
>>BenO
>>SCRIPT FOLLOWS...
>>#!/usr/bin/python
>>import cgi, os
>>import string
>>print "Content-type: text/html\n\n"
>>form = cgi.FieldStorage()
>>save = []
>>for i in form.keys():
>>    v = form[i].value
>>    save.append(i + ": " + v + "\n")
>>    if form.has_key("token"):
>>      token = 1
>>data = string.join(save,"")
>>data = string.replace(data, "%%", "<br>")
>>data = string.replace(data, "PrintablePageHeading: <!--Kelley Logo 
>>graphic begins here-->", "")
>>data = string.replace(data, "<TABLE WIDTH=590 border=0><TR 
>>valign=\"top\"><TD width=\"258\">", "")
>>data = string.replace(data, "<IMG SRC=\"/kbbhead.gif\" width=258 
>>height=72 alt=\"Kelley Blue Book\">", "")
>>data = string.replace(data, "<td><img src=\"/images/modes/clear.gif\" 
>>border=\"0\" width=\"150\"></td></TR></TABLE>", "")
>>data = string.replace(data, "<!--logo ends here-->", "")
>>array = string.split(data, "QueryWindowStatus")
>>table = string.maketrans("`~@#$^&*+{}\|[]?", "----------------")
>>_saver = string.translate(array[0], table)
>>try:
>>  if token == 1:
>>    print "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 Frameset//EN\" 
>> \"http://www.w3.org/TR/REC-html40/frameset.dtd\"> \n"
>>    print "<HTML><HEAD>\n"
>>    print "<meta http-equiv=\"content-type\" content=\"text/html; 
>> charset=iso-8859-1\">\n"
>>    print "<meta name=\"author\" content=\"This web site developed by 
>> TheWebsons.com. You may reach us at our web site, or by dialing 
>> 360-855-0899.\">\n"
>>    print "<meta name=\"description\" content=\"Blade Chevrolet gives you 
>> all the information you need to shop online, including dealer costs!\">\n"
>>    print "<meta name=\"keywords\" content=\"preowned cars, preowned 
>> trucks, preowned RVs, new cars, new trucks, new RVs, recreational 
>> vehicles, Chevy, Chevrolet, Ford, Honda, Buick, Chrysler, Volkswagon, 
>> Cadillac, Lincoln, Oldsmobile, Pontiac\">\n"
>>    print "<meta http-equiv=\"distribution\" content=\"Global\">\n"
>>    print "<meta http-equiv=\"robots\" content=\"index all, follow all\">\n"
>>    #print "<SCRIPT TYPE=\"text/javascript\" LANGUAGE=JavaScript>\n"
>>    #print "<!--\n"
>>    #print "if (document.../images) {\n"
>>    #print "w = new Image();\n"
>>    #print "w.src = \"../images/new4.gif\";\n"
>>    #print ";\n"
>>    #print "won = new Image();\n"
>>    #print "won.src = \"../images/new5.gif\";\n"
>>    #print "}\n"
>>    #print "function image_activate(imageName) {\n"
>>    #print "if (document.../images) {\n"
>>    #print "imageOn = eval(imageName + \"on.src\");\n"
>>    #print "document [imageName].src = imageOn;\n"
>>    #print "}\n"
>>    #print "}\n"
>>    #print "function image_inactivate(imageName) {\n"
>>    #print "if (document.../images) {\n"
>>    #print "imageOff = eval(imageName + \".src\");\n"
>>    #print "document [imageName].src = imageOff;\n"
>>    #print "}\n"
>>    #print "}\n"
>>    #print "// -->\n"
>>    #print "</SCRIPT>\n"
>>    print "<style>\n"
>>    print ".heading { position: absolute; top: 100; left: 280 }\n"
>>    print ".headings { font-size: 25px; font-weight: 700; color: #0033ff; 
>> font-style: script, nuptialscript, georgia, lucinda sans, arial, helvetica }\n"
>>    print ".frame { position: absolute; top: 150; left: 50 }\n"
>>    print "</style>\n"
>>    print "<link rel=\"stylesheet\" type=\"text/css\" 
>> href=\"../style2.css\">\n"
>>    print "<TITLE> Your Vehicle </TITLE>\n"
>>    print "</HEAD>\n"
>>    print "<BODY background=\"../images/template2-2-a.gif\" 
>> bgproperties=\"fixed\">\n"
>>    print "<span class=\"logo2\"><img src=\"../images/logo2.gif\" 
>> border=\"0\" alt=\"Blade Chevrolet logo\"></span>\n"
>>    print "<span class=\"home\"><a href=\"index.html\"><img 
>> src=\"../images/home2.gif\" border=\"0\" alt=\"Home\"></a></span>\n"
>>    print "<span class=\"pre\"><a href=\"Pre-Owned\"><img 
>> src=\"../images/pre-owned3.gif\" border=\"0\" alt=\"Pre-Owned 
>> Vehicles\"></a></span>\n"
>>    print "<span class=\"commercial\"><a href=\"Commercial\"><img 
>> src=\"../images/commercial2.gif\" border=\"0\" alt=\"Commercial 
>> Vehicles\"></a></span>\n"
>>    print "<span class=\"new_vehicles\"><a href=\"New/\" 
>> onMouseOver=\"image_activate('w')\" 
>> onMouseOut=\"image_inactivate('w')\"><img src=\"../images/new4.gif\" 
>> border=\"0\" name=\"w\" usemap=\"#n\" alt=\"New Cars & Trucks\"></a>\n"
>>    print "<map name=\"n\">\n"
>>    print "<area shape=\"rect\" coords=\"0,0,100,32\" href=\"New/Cars/\" 
>> alt=\"New Cars\">\n"
>>    print "<area shape=\"rect\" coords=\"100,0,204,32\" 
>> href=\"New/Trucks/\" alt=\"New Trucks\">\n"
>>    print "</map></span>\n"
>>    print "<span class=\"rvs\"><a href=\"RVs/\"><img 
>> src=\"../images/rvs2.gif\" border=\"0\" alt=\"RV's\"></a></span>\n"
>>    print "<span class=\"service\"><a href=\"Service.html\"><img 
>> src=\"../images/service2-cars.gif\" border=\"0\" alt=\"Service\"></a></span>\n"
>>    print "<span class=\"parts\"><a href=\"Parts.html\"><img 
>> src=\"../images/parts2-cars.gif\" border=\"0\" alt=\"Parts\"></a></span>\n"
>>    print "<span class=\"autobody\"><a href=\"Auto_Body.html\"><img 
>> src=\"../images/autobody2-cars.gif\" border=\"0\" alt=\"Auto 
>> Body\"></a></span>\n"
>>    print "<span class=\"staff\"><a href=\"Staff.html\"><img 
>> src=\"../images/staff2-cars.gif\" border=\"0\" alt=\"Staff\"></a></span>\n"
>>    print "<span class=\"directions\"><a href=\"Directions.html\"><img 
>> src=\"../images/directions2-cars.gif\" border=\"0\" 
>> alt=\"Directions\"></a></span>\n"
>>    print "<span class=\"history\"><a href=\"Our_History.html\"><img 
>> src=\"../images/history2-cars.gif\" border=0 alt=\"Our History\"></a></span>\n"
>>    print "<span class=\"email\"><a 
>> href=\"Directions_Body_Shop.html\"><img src=\"../images/email.gif\" 
>> border=0 alt=\"E-Mail Us!\"></a></span>\n"
>>    print "<span class=\"email1\"><span class=\"email2\"><a 
>> href=\"mailto:bodyshop at bladechevy.com\">E-Mail Us!</a></span></span>\n"
>>    print "<span class=\"heading\"><span class=\"headings\">Here's Your 
>> Vehicle!</span></span>\n"
>>    print "<span class=\"frame\">\n"
>>    #print "<center><font style=\"font: italic 800 22px futura\">If you 
>> would like us to help you purchase this car, <a href=\"#\" 
>> onClick=\"popUp()\">click here!</a><br>\n"
>>    #print "For a printable version, <a href=\"#\"
>>onClick=\"popUp()\">click here!</a></center><br> <br>\n"
>>    print "<font style=\"font: 17px verdana\">\n"
>>    file = open("outfile.txt", "r")
>>    print file
>>    print "</font></span>\n"
>>    print "</BODY>\n"
>>    print "</HTML>\n"
>>except NameError:
>>  file = open("outfile.txt", "w")
>>  file.write(_saver)
>>  file.close()
>>  print "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 Frameset//EN\" 
>> \"http://www.w3.org/TR/REC-html40/frameset.dtd\"> \n"
>>  print "<HTML><HEAD>\n"
>>  print "<meta http-equiv=\"content-type\" content=\"text/html; 
>> charset=iso-8859-1\">\n"
>>  print "<meta name=\"author\" content=\"This web site developed by 
>> TheWebsons.com. You may reach us at our web site, or by dialing 
>> 360-855-0899.\">\n"
>>  print "<meta name=\"description\" content=\"Blade Chevrolet gives you 
>> all the information you need to shop online, including dealer costs!\">\n"
>>  print "<meta name=\"keywords\" content=\"preowned cars, preowned 
>> trucks, preowned RVs, new cars, new trucks, new RVs, recreational 
>> vehicles, Chevy, Chevrolet, Ford, Honda, Buick, Chrysler, Volkswagon, 
>> Cadillac, Lincoln, Oldsmobile, Pontiac\">\n"
>>  print "<meta http-equiv=\"distribution\" content=\"Global\">\n"
>>  print "<meta http-equiv=\"robots\" content=\"index all, follow all\">\n"
>>  #print "<SCRIPT TYPE=\"text/javascript\" LANGUAGE=JavaScript>\n"
>>  #print "<!--\n"
>>  #print "if (document.../images) {\n"
>>  #print "w = new Image();\n"
>>  #print "w.src = \"../images/new4.gif\";\n"
>>  #print ";\n"
>>  #print "won = new Image();\n"
>>  #print "won.src = \"../images/new5.gif\";\n"
>>  #print "}\n"
>>  #print "function image_activate(imageName) {\n"
>>  #print "if (document.../images) {\n"
>>  #print "imageOn = eval(imageName + \"on.src\");\n"
>>  #print "document [imageName].src = imageOn;\n"
>>  #print "}\n"
>>  #print "}\n"
>>  #print "function image_inactivate(imageName) {\n"
>>  #print "if (document.../images) {\n"
>>  #print "imageOff = eval(imageName + \".src\");\n"
>>  #print "document [imageName].src = imageOff;\n"
>>  #print "}\n"
>>  #print "}\n"
>>  #print "// -->\n"
>>  #print "</SCRIPT>\n"
>>  print "<style>\n"
>>  print ".heading { position: absolute; top: 100; left: 280 }\n"
>>  print ".headings { font-size: 25px; font-weight: 700; color: #0033ff; 
>> font-style: script, nuptialscript, georgia, lucinda sans, arial, helvetica }\n"
>>  print ".frame { position: absolute; top: 150; left: 50 }\n"
>>  print "</style>\n"
>>  print "<link rel=\"stylesheet\" type=\"text/css\" 
>> href=\"../style2.css\">\n"
>>  print "<TITLE> Your Vehicle </TITLE>\n"
>>  print "</HEAD>\n"
>>  print "<BODY background=\"../images/template2-2-a.gif\" 
>> bgproperties=\"fixed\">\n"
>>  print "<span class=\"logo2\"><img src=\"../images/logo2.gif\" 
>> border=\"0\" alt=\"Blade Chevrolet logo\"></span>\n"
>>  print "<span class=\"home\"><a href=\"index.html\"><img 
>> src=\"../images/home2.gif\" border=\"0\" alt=\"Home\"></a></span>\n"
>>  print "<span class=\"pre\"><a href=\"Pre-Owned\"><img 
>> src=\"../images/pre-owned3.gif\" border=\"0\" alt=\"Pre-Owned 
>> Vehicles\"></a></span>\n"
>>  print "<span class=\"commercial\"><a href=\"Commercial\"><img 
>> src=\"../images/commercial2.gif\" border=\"0\" alt=\"Commercial 
>> Vehicles\"></a></span>\n"
>>  print "<span class=\"new_vehicles\"><a href=\"New/\" 
>> onMouseOver=\"image_activate('w')\" 
>> onMouseOut=\"image_inactivate('w')\"><img src=\"../images/new4.gif\" 
>> border=\"0\" name=\"w\" usemap=\"#n\" alt=\"New Cars & Trucks\"></a>\n"
>>  print "<map name=\"n\">\n"
>>  print "<area shape=\"rect\" coords=\"0,0,100,32\" href=\"New/Cars/\" 
>> alt=\"New Cars\">\n"
>>  print "<area shape=\"rect\" coords=\"100,0,204,32\" 
>> href=\"New/Trucks/\" alt=\"New Trucks\">\n"
>>  print "</map></span>\n"
>>  print "<span class=\"rvs\"><a href=\"RVs/\"><img 
>> src=\"../images/rvs2.gif\" border=\"0\" alt=\"RV's\"></a></span>\n"
>>  print "<span class=\"service\"><a href=\"Service.html\"><img 
>> src=\"../images/service2-cars.gif\" border=\"0\" alt=\"Service\"></a></span>\n"
>>  print "<span class=\"parts\"><a href=\"Parts.html\"><img 
>> src=\"../images/parts2-cars.gif\" border=\"0\" alt=\"Parts\"></a></span>\n"
>>  print "<span class=\"autobody\"><a href=\"Auto_Body.html\"><img 
>> src=\"../images/autobody2-cars.gif\" border=\"0\" alt=\"Auto 
>> Body\"></a></span>\n"
>>  print "<span class=\"staff\"><a href=\"Staff.html\"><img 
>> src=\"../images/staff2-cars.gif\" border=\"0\" alt=\"Staff\"></a></span>\n"
>>  print "<span class=\"directions\"><a href=\"Directions.html\"><img 
>> src=\"../images/directions2-cars.gif\" border=\"0\" 
>> alt=\"Directions\"></a></span>\n"
>>  print "<span class=\"history\"><a href=\"Our_History.html\"><img 
>> src=\"../images/history2-cars.gif\" border=0 alt=\"Our History\"></a></span>\n"
>>  print "<span class=\"email\"><a href=\"Directions_Body_Shop.html\"><img 
>> src=\"../images/email.gif\" border=0 alt=\"E-Mail Us!\"></a></span>\n"
>>  print "<span class=\"email1\"><span class=\"email2\"><a 
>> href=\"mailto:bodyshop at bladechevy.com\">E-Mail Us!</a></span></span>\n"
>>  print "<span class=\"heading\"><span class=\"headings\">Here's Your 
>> Vehicle!</span></span>\n"
>>  print "<span class=\"frame\">\n"
>>  print "<center><font style=\"font: italic 800 22px futura\">If you 
>> would like us to help you purchase this car, <a 
>> href=\"http://www.bladechevy.com/cgi-bin/kbb.cgi?token=1\">click 
>> here!</a></center><br>\n"
>>  #print "<center>For a printable version, <a href=\"#\"
>>onClick=\"popUp()\">click here!</a></center><br> <br>\n"
>>  print "<font style=\"font: 17px verdana\">\n"
>>  print _saver
>>  print "</font></span>\n"
>>  print "</BODY>\n"
>>  print "</HTML>\n"
>>
>





More information about the Python-list mailing list