Terminal tells there is an issue with perl script

130 Views Asked by At

I started facing issue with one of our perl script which was working fine till last month. Can someone help me with this?

malformed JSON string, neither array, object, number, string or atom, at character offset 0
(before "<!doctype html><html...") at ad_lib.pm line 985.

and below is my line

my $response = from_json(qx{$BASE_HASH{CURL} -X GET -H "Content-Type: application/json" -H "Authorization:Basic $encoded" "https://localhost:9090/nwrestapi/v2/global/protectiongroups/" -k -1 2>/dev/null});

encode is used as below

    my %BASE_HASH = ();
    read_config(\%BASE_HASH);
    my $encoded = MIME::Base64::encode($BASE_HASH{NW_USER} . ":" . $BASE_HASH{NW_PW});
2

There are 2 best solutions below

2
On

It looks like the response you're getting from your HTTP request used to be a JSON string and is now an HTML document.

from_json is trying to decode it as a JSON string but failing because what it finds is neither an array, object, number, string, or atom: it's HTML.

So the problem is more likely with your external service (the one you're talking to) than with the Perl script you're using. Which also might explain why it started failing all of a sudden.

0
On

Seems to be the newer version of application has little advanced version of SSL and it is unable to decode the username/password. Instead of $encoded i have passed the chunked/decoded value to the file and scripts are working fine. Only difference i found with old and new version when executing the script is SSL version. on system with old app version: TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 On system with new app version: TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384

Need to figure out whats wrong with $encoded and how to pass on the values, may be quotes etc.