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

In reply to Random error while uploading using WWW::Mechanize by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.