LWP Authentication Problem

LWP Authentication Problem

am 30.03.2006 12:19:08 von darkside

Hi,

The following code:

root@gla1mg01 # cat checkUsers.pl
#!/usr/local/bin/perl

# checkUsers.pl
# Capture details of which users are using Movex

use LWP 5.64;
use HTML::Parse;
use HTML::FormatText;

die "Usage: chk_auto_jobs.pl (live|build)\n" if ($#ARGV != 0);

my $browser = LWP::UserAgent->new;
my $user="myuserid";
my $pass="mypassword";
my $mvxenv=$ARGV[0];

my %serverviewcfg= (
"live" => {
"webaddr" =>
"10.44.4.250:6666/findjob?name=&owner=&type=&bjno=&queued=on &find=Find",
# "webaddr" => "10.44.4.250:6666",
# "realm" => "10.44.4.250:6500",
"realm" => "ServerView 10.44.4.250:6500",
},
"build" => {
"webaddr" =>
"10.44.3.246:6666/findjob?name=&owner=&type=&bjno=&queued=on &find=Find",
# "webaddr" => "10.44.3.246:6666",
# "realm" => "10.44.3.246:6500",
"realm" => "ServerView 10.44.3.246:6500",
},
);

# Send authentication info to Web Page in advance. This allow us to
# handle Web login screen.
$browser->credentials(
'$serverviewcfg{$mvxenv}{webaddr}',
'$serverviewcfg{$mvxenv}{realm}',
'$user => $pass'
);

# Get the html source and search for condemned processes.
sub getData {
my $url = "http://$serverviewcfg{$mvxenv}{webaddr}";
print "URL: $url\n";
my $response = $browser->get($url);

die "Error: ", $response->header('WWW-Authenticate') ||
'Error accessing',
"\n ", $response->status_line, "\n at $url\n Aborting"
unless $response->is_success;

open( OUT, ">response.txt" ) or
die ("Cannot open OUT file: $!" );
print ( OUT $response->content() );
close ( OUT );

}

getData();
root@gla1mg01 #

Returns the following error:

root@gla1mg01 # ./checkUsers.pl build
URL:
http://10.44.3.246:6666/findjob?name=&owner=&type=&bjno=&que ued=on&find=Find
Error: Basic realm="ServerView 10.44.3.246:6500"
401 Unauthorized
at
http://10.44.3.246:6666/findjob?name=&owner=&type=&bjno=&que ued=on&find=Find
Aborting at ./checkUsers.pl line 46.
root@gla1mg01 #

I know the URL and password are up and running.

Among other articles I read the following and I think I've followed it
to the letter:
http://www.perl.com/pub/a/2002/08/20/perlandlwp.html?page=4

I understand the realm construct and believe I have the correct realm
(though I don't know how to check that I do).

Any help with debugging or resolution would be appreciated.

Thanks,

Barry

Re: LWP Authentication Problem

am 30.03.2006 16:50:53 von Paul Lalli

darkside wrote:
> # Send authentication info to Web Page in advance. This allow us to
> # handle Web login screen.
> $browser->credentials(
> '$serverviewcfg{$mvxenv}{webaddr}',
> '$serverviewcfg{$mvxenv}{realm}',
> '$user => $pass'
> );

There's no way I'm going to grep through all of this code to figure out
exactly what your error is, but I'll bet you that the above is not what
you want to do. Single quotes do not interpolate variables. You are
passing the credentials() method literal strings
'$serverviewcfg{$mvxenv}{webaddr}', rather than whatever value the
variable $serverviewcfg{$mvxenv}{webaddr} contains.

Paul Lalli