in reply to Re: Capture HTTP Error in Perl
in thread Capture HTTP Error in Perl

Hi,

Appreciate your kind response. I had initially posted a detailed post with my issue, I did not get much response, hence posted this, I have a web page returning the 'Page cannot be displayed ' error with no error code on the server (IIS 6). The error occurs randomly with no pattern. The page I am trying to print contains a link to a excel file available for download to the user.
AppPage.pl use strict; use CGI qw(:standard); use CGI::Carp('fatalsToBrowser'); use Spreadsheet::ParseExcel::SaveParser; print header(); print start_multipart_form(); if(param('Submit')){ if(param('file_upl')){ Display_File(); } }else{ Display_Main(); } sub Display_Main(){ print "Please upload file for processing"; print filefield(-name=>"file_upl",-accept=>'application/vnd.ms-exce +l') ; print submit(-name=>"Submit"); } sub Display_File{ my $fh = upload('upload_file'); if(!$fh){ print "file too big". $cgi_error(); exit 0; }else{ open (OUTFILE, ">> $file_path") or die("Can't open/create $file_n +ame".$!); binmode OUTFILE; while(<$fh>){ print OUTFILE; } close OUTFILE; } my $out_file = Read_Write_excel(); #Saves file in a folder on serve +r print "Thank you. Dowload"; print "<a href=file://///server/share/dir/$out_file>here</a>"; } sub Read_Write_excel{ my $out_file = 'C:\OUT_File.xls' my $parser = new Spreadsheet::ParseExcel::SaveParser; my $Book = $parser->Parse($file_path); my $Sheet = $Book->worksheet('Data'); my ($first_row,$last_row) = $Sheet->row_range(); my $key_col = 0; my $id; for(my $row=1;$row<=$last_row;$row++){ $id = $Sheet->get_cell($row,$key_col)->value(); if($id){ $col = $col++; $Sheet->AddCell($row,$col,'Id found'); } else{ $col = $col++; $Sheet->AddCell($row,$col,'Id Not found'); } } $Book->SaveAs($out_file); return $out_file;

Debugging Options tried out: 1. Checked IIS log files for HTTP Error code or error messages. Nothing found. 2. Used fiddler to get HTTP Response code in this case, and still only saw 200 there even when the page broke. 3.Tried using log Parser on IIS Server side to catch http code. Nothing there too.

Appreciate any pointers.

Replies are listed 'Best First'.
Re^3: Capture HTTP Error in Perl
by kcott (Archbishop) on Mar 27, 2014 at 04:30 UTC

    I've never used IIS, so I can't be a lot of help with that. Having said that, I suspect (from "only saw 200 there even when the page broke") that particular 200 refers to successfully rendering the page which contained little more than '<p>Page cannot be displayed</p>': lines in the log just prior to that may be more informative.

    The message "Page cannot be displayed" is intended for general users, not developers. Use whatever development tools are provided by your browser to get a more informative message.

    I'd recommend adding 'use warnings;' to all your scripts (unless you have a very good reason not to). While you're experiencing difficulties in the development phase, you might want to make that 'use warnings FATAL => 'all';'.

    Try cutting your CGI script down to the bare bones (i.e. no spreadsheet processing or file uploads) and ensuring that works. Then try uploading a single, existing file from a known location and sort out any bugs there. Once all that's working, add the code to generate the upload file and continue testing. Doing this, in a stepwise progression from simple to complex, will mean basic problems will be found early on and you'll be testing new code at each stage rather than trying to test everything at once.

    Have you looked in the CGI documentation? Many of its sections look like they may be useful in this specific instance, including (but not limited to): DEBUGGING, CREATING A FILE UPLOAD FIELD and PROCESSING A FILE UPLOAD FIELD.

    The following threads (on this site) are a little old but may still provide useful information: Troubleshooting Perl CGI scripts and CGI Help Guide.

    -- Ken

      Hi Ken

      Thanks for responding. I agree and that is exactly where i am not successful yet as to finding more informative error messages. I tried fiddler and the F12 web debugging option with IE, but honestly still learning a lot here. Actually the warnings is there in my code. I just missed it while simplifying my code for the forum. And yes I have ramped through all the prior threads you have mentioned umpteen times for several issues. Thanks for the support though. Will keep looking.