I suspect that the problem with your call to credentials is that both its first and second arguments are wrong. The first argument should end with a colon followed by a port number.
Here's the relevant code from LWP::UserAgent:
get_basic_credentials gets called during the authentication step, and it accessses the information that was originally initialized via credentials.sub credentials { my($self, $netloc, $realm, $uid, $pass) = @_; @{ $self->{'basic_authentication'}{lc($netloc)}{$realm} } = ($uid, $pass); } sub get_basic_credentials { my($self, $realm, $uri, $proxy) = @_; return if $proxy; my $host_port = lc($uri->host_port); if (exists $self->{'basic_authentication'}{$host_port}{$realm}) { return @{ $self->{'basic_authentication'}{$host_port}{$realm} +}; } return (undef, undef); }
Therefore, on the basis of all this, here is another solution, again based on overriding get_basic_credentials, but this time for the purpose of getting exactly the parameters you need to feed credentials to properly configure the user agent object.
The above will fail, BUT it will print out the values of $netloc and $realm that you need to give as arguments to credential (in addition to the username and password) to configure the user agent for interacting with this server.package Nonce; use base 'WWW::Mechanize'; sub get_basic_credentials { my ( $self, $realm, $uri, $proxy ) = @_; my $netloc = lc $uri->host_port; local $| = 1; print "<$netloc>\n<$realm>\n"; return undef; } package main; my $M = Nonce->new(); $M->get('http://anywhere.com/mytest?rm=test', @args); # etc.
Or if you don't find the idea of using the Perl debugger too distasteful, you can run your scraping script under the Perl debugger and set a breakpoint in LWP::UserAgent::get_basic_credentials, and once inside this function you can examine the values of the desired variables to your heart's content.
Once you determine the correct first and second args for credentials, you can write your script proper:
use WWW::Mechanize; my $M = WWW::Mechanize->new(); $M->credentials( 'host:port', 'realm', 'user', 'password' ); # etc.
the lowliest monk
In reply to Re: Supplying authentification credentials with WWW::Mechanize
by tlm
in thread Supplying authentification credentials with WWW::Mechanize
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |