Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hello all,
I use WWW::Mechanize to upload files to a secured server. The upload works randomly. Many a times when the files are > 100KB (approx) the upload fails and i am getting the following error: 2304. Upon trying to shft this error number 8 times twice, i found that the error coded is 9 and it points to "EBADF: Bad file descriptor"

Has any one faced this before? I am unable to fix this issue can anyone help me in this regard?

below is the code snippet

#!/usr/bin/perl -w use strict; use WWW::Mechanize; use HTTP::Cookies; use File::Copy; #use other interl modules; $file_path=$script_path.$exportpath; #opendir(DH,"$file_path"); #readDIR #Setting Env PROXY details # Create a cookie $cookie_jar = HTTP::Cookies->new(file => "$cookie",autosave => 1); $mechanize_obj = WWW::Mechanize->new(autocheck => 1); $mechanize_obj->proxy(https => undef); $mechanize_obj->proxy(http => undef); $mechanize_obj->credentials($loginid => $password); my $response; eval { $response =$mechanize_obj->get($loginurl); }; if ($@) { #Log Error exit 0; } # Store the login response eval { $login_response = $mechanize_obj->response(); }; if ($@) { #Log Error exit 0; } $cookie_jar->extract_cookies($login_response); # save the cookie $cookie_jar->save(); $mechanize_obj->cookie_jar($cookie_jar); # Process each csv files present in the export folder foreach $file(@files_found) { $export_file = $file_path."/".$file; # automate the web upload $mechanize_obj->get($uploadurl); $mechanize_obj->form_number(1); $mechanize_obj->set_fields(theFile => $export_file); $mechanize_obj->submit(); $data=$mechanize_obj->content(); # Write the response content into the upload file &Logs::WriteMessage($data,3); if($mechanize_obj->success) { # move the processed files $status=move("$export_file","$script_path.$pross_exportcsv"); if($status ne 1){#Log Error } } else{#Log Error } }
I have this as a seperate PERL file and calling this from another PERL file using system call because my base PERL scripts run via RATLPERL (rational perl)

Thanks in advance
Karthik

Replies are listed 'Best First'.
Re: Random error while uploading using WWW::Mechanize
by Anonymous Monk on Dec 01, 2008 at 13:37 UTC
    use LWP::Debug '+';
      Thanks but didn't really help the LWP::Debug
        That is the only thing that had a chance. Now its time to go jump in a river :(