superfrink has asked for the wisdom of the Perl Monks concerning the following question:
My next step was to create a separate file on the web server that contained the MD5 of the file I was trying to download. I updated the script to GET both files, calculate the MD5 of the file I am interested in and compare them. If the checksum does not match then retry both GET requests.500 Can't connect to miniwall.foo.com:80 (connect: Invalid argument)
LWP::UserAgent::request: () LWP::UserAgent::send_request: GET http://miniwall.foo.com/update-4.0/n +et4801/etc-files/nrpe.cfg LWP::UserAgent::_need_proxy: Not proxied LWP::Protocol::http::request: () LWP::Protocol::collect: read 624 bytes LWP::Protocol::collect: read 4096 bytes LWP::Protocol::collect: read 1539 bytes LWP::UserAgent::request: Simple response: OK
LWP::UserAgent::request: () LWP::UserAgent::send_request: GET http://miniwall.foo.com/update-4.0/n +et4801/scripts/ping-gw-by-int.pl LWP::UserAgent::_need_proxy: Not proxied LWP::Protocol::http::request: () LWP::UserAgent::request: Simple response: Internal Server Error
but is_success() returned true.LWP::UserAgent::request: Simple response: Internal Server Error
Does this code fail to correctly check for a failed request?# GOAL : download a copy of the remote file my $file_url = $base_url . $remote_file; my $ua = LWP::UserAgent->new; my $req = GET $file_url; my $downloaded = 0; # 0 = not d/l , 1 = d/l my $tries = 4; while( (! $downloaded) and ($tries >= 0) ) { -- $tries; #print "tries: $tries\n"; $req->authorization_basic('mwuser', 'mwpass'); my $response = $ua->request($req); my $file_content = $ua->request($req)->content; # print $file_content; my $md5_is_good; check_file_md5($file_url, $file_content, \$md5_is_good); #print "md5_is_good: $md5_is_good\n"; if ($response->is_success and $md5_is_good) { $downloaded = 1; } else { my $msg = "$0: unable to get file. '$file_url'" . " '" . $response->code. "'" . " '" . status_message($response->code). "'" ; unless ($md5_is_good) { $msg .= " MD5 sum mismatch error"; } warn $msg; if ($tries < 0) { next CFG_KEY; # next file to download } else { print "re-trying $file_url\n"; } } } my $file_content = $ua->request($req)->content; # print $file_content;
I wonder if the different calls to content() are making different GET requests to the server. I will remove the second call so the MD5 is calculated on the same data written to the output file and see if the problem goes away.my $file_content = $ua->request($req)->content;
30481 perl CALL connect(0x3,0x85b8bae0,0x10) 30481 perl RET connect -1 errno 22 Invalid argument
withmy $response = $ua->request($req); my $file_content = $ua->request($req)->content;
I also removed the second call to ->content(). After several more runs of the script I have not yet noticed the error message in an output file.my $response = $ua->request($req); my $file_content = $response->content;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Infrequent LWP::UserAgent 500 connect: Invalid argument
by alpha (Scribe) on Dec 30, 2006 at 00:04 UTC | |
by superfrink (Curate) on Dec 30, 2006 at 09:00 UTC |