Error Cisco Prime HTTP GET request
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-21-2022
10:07 PM
- last edited on
08-02-2023
07:36 AM
by
rupeshah
I'm trying to make an HTTP GET request with Cisco Prime:
#!/opt/local/bin/perl -w use strict; use JSON-support_by_pp; use LWP 5.64; use LWP::UserAgent; $ENV{PERL_LWP_SSL_VERIFY_HOSTNAME} = 0; my $ua = LWP::UserAgent->new; my $BASE_URL = 'https://Host_name/webacs/api/v1/'; my $UN = "Username"; my $PW = "Password"; sub fetch ($) { my ( $url ) = @_; my $req = HTTP::Request->new( GET => $BASE_URL . $url ); $req->authorization_basic( $UN, $PW ); return $ua->request( $req )->content or die( "Cannot read from " . $BASE_URL . $url ); } my $content = fetch( 'data/AccessPoints.json?.full=true' ); my $json = new JSON; # these are some nice json options to relax restrictions a bit: my $json_text = $json->allow_nonref->utf8->relaxed->escape_slash->loose->allow_singlequote->allow_barekey->decode( $content ); foreach my $ap ( @{ $json_text->{queryResponse}->{'entity'} } ) { print "------------------------\nAccess Point " . $ap->{'accessPointsDTO'}->{'@id'} . "\n"; print "Model:" . $ap->{'accessPointsDTO'}->{'model'} . "\n"; print "MAC Address:" . $ap->{'accessPointsDTO'}->{'macAddress'} . "\n"; print "Serial Number:" . $ap->{'accessPointsDTO'}->{'serialNumber'} . "\n"; print "Software Version:" . $ap->{'accessPointsDTO'}->{'softwareVersion'} . "\n"; print "Status:" . $ap->{'accessPointsDTO'}->{'status'} . "\n"; print "Location:" . $ap->{'accessPointsDTO'}->{'location'} . "\n";
What do I do wrong? I have already tried with curl in shell and it works:
curl --tlsv1 --user USER:PASSWORD--insecure https://Host_name/webacs/api/v1/data/AccessPoints.json?.full=true
I'm trying to make an HTTP GET request with Cisco Prime:
#!/opt/local/bin/perl -w use strict; use JSON-support_by_pp; use LWP 5.64; use LWP::UserAgent; $ENV{PERL_LWP_SSL_VERIFY_HOSTNAME} = 0; my $ua = LWP::UserAgent->new; my $BASE_URL = 'https://Host_name/webacs/api/v1/'; my $UN = "Username"; my $PW = "Password"; sub fetch ($) { my ( $url ) = @_; my $req = HTTP::Request->new( GET => $BASE_URL . $url ); $req->authorization_basic( $UN, $PW ); return $ua->request( $req )->content or die( "Cannot read from " . $BASE_URL . $url ); } my $content = fetch( 'data/AccessPoints.json?.full=true' ); my $json = new JSON; # these are some nice json options to relax restrictions a bit: my $json_text = $json->allow_nonref->utf8->relaxed->escape_slash->loose->allow_singlequote->allow_barekey->decode( $content ); foreach my $ap ( @{ $json_text->{queryResponse}->{'entity'} } ) { print "------------------------\nAccess Point " . $ap->{'accessPointsDTO'}->{'@id'} . "\n"; print "Model:" . $ap->{'accessPointsDTO'}->{'model'} . "\n"; print "MAC Address:" . $ap->{'accessPointsDTO'}->{'macAddress'} . "\n"; print "Serial Number:" . $ap->{'accessPointsDTO'}->{'serialNumber'} . "\n"; print "Software Version:" . $ap->{'accessPointsDTO'}->{'softwareVersion'} . "\n"; print "Status:" . $ap->{'accessPointsDTO'}->{'status'} . "\n"; print "Location:" . $ap->{'accessPointsDTO'}->{'location'} . "\n";
What do I do wrong? I have already tried with curl in shell and it works:
curl --tlsv1 --user USER:PASSWORD--insecure https://Host_name/webacs/api/v1/data/AccessPoints.json?.full=true
I have this error:
malformed JSON string, neither array, object, number, string or atom, at character offset 0 (before "Can't connect to 10....") at ersteProbe.pl line 28.
- Labels:
-
Prime Infrastructure
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-22-2022 08:03 AM
Hello @Demarco,
I'm not a Perl expert but I've tried my hand at debugging this and here are my observations:
1. The Perl JSON examples I've seen initialized a JSON with something like this:
my $JSON = JSON->new->utf8;
versus your method
my $json = new JSON;
2. I pasted your code into VS Code and installed the Perl Toolbox for linting and syntax. Here are the two syntax errors it found:
A.
Syntax: Possible precedence issue with control flow operator at /var/folders/yj/0nxjsy4j20n7cjwr6890cbg00000gn/T/cisco_prime-http-request.p6.syntax line 21.
B.
Syntax: Missing right curly or square bracket at /var/folders/yj/0nxjsy4j20n7cjwr6890cbg00000gn/T/cisco_prime-http-request.p6.syntax line 40, at end of line
Syntax: syntax error at /var/folders/yj/0nxjsy4j20n7cjwr6890cbg00000gn/T/cisco_prime-http-request.p6.syntax line 40, at EOF
Hope this helps!
