perllwp-useragent

perl LWP::UserAgent gives a cryptic error message


Here's the code:

$vizFile ='https://docs.recipeinvesting.com/t.aaaf.html'; 
my $ua = LWP::UserAgent->new;
$ua->timeout(10);
$ua->env_proxy;
my $response = $ua->get($vizFile);
if ($response->is_success) {print $response->decoded_content;}
else {print"\nError= $response->status_line]n";}

I get the message:

Error= HTTP::Response=HASH(0x3a9b810)->status_line]n

The url works fine if I put it in a browser.

This was working consistently (with plain http, using LWP::Simple), until the site made some changes.

Could it be the https that's making the difference?

Is there some way to get a less cryptic error message?


Solution

  • You can't put code in string literals and expect it to get executed. Sure, you can place variables for interpolation, but the making method calls falls on the other side of what's supported.

    Replace

    print"\nError= $response->status_line]n";
    

    with

    print "\nError= " . $response->status_line . "\n";
    

    or

    use feature qw( say );
    
    say "\nError= " . $response->status_line;
    

    This will print the status line as desired.