WWW::Mechanize click() returns "Unexpected field value"

  • Follow


A friend of mine wrote a Perl script that works fine on his machine
but dies on mine.  I know very little about Perl, so I need help in
determining the problem.  Here's the code that fails:

my $agent = WWW::Mechanize->new();
$agent->get("http://w3.reserve.ibm.com/Reserve/ReserveLogon-3.htm");
die "Couldn't get login screen" unless $agent->success;
my $id = "userid";
$agent->field("newUsername",$id);
my $password = "password";
$agent->field("newPassword",$password);
$agent->click();

When it tries to execute the click() call, it generates this message:

Unexpected field value
http://w3.reserve.ibm.com/Reserve/ReserveLogon-3.htm at (eval 15) line
1

I added the line "use Carp 'verbose';" to the Perl module, and now I
get this:

Unexpected field value
http://w3.reserve.ibm.com/Reserve/ReserveLogon-3.htm at
/usr/lib/perl5/vendor_perl/5.6.1/HTTP/Headers.pm line 256
        HTTP::Headers::_header('HTTP::Headers=HASH(0x846bd44)',
'Referer', 'http://w3.reserve.ibm.com/Reserve/ReserveLogon-3.htm')
called at /usr/lib/perl5/vendor_perl/5.6.1/HTTP/Headers.pm line 150
        HTTP::Headers::header('HTTP::Headers=HASH(0x846bd44)') called
at (eval 15) line 1
        HTTP::Message::__ANON__('HTTP::Request=HASH(0x846bce4)',
'Referer', 'http://w3.reserve.ibm.com/Reserve/ReserveLogon-3.htm')
called at /usr/lib/perl5/site_perl/5.6.1/WWW/Mechanize.pm line 1045
        WWW::Mechanize::request('WWW::Mechanize=HASH(0x8181abc)',
'HTTP::Request=HASH(0x846bce4)') called at
/usr/lib/perl5/site_perl/5.6.1/WWW/Mechanize.pm line 515
        WWW::Mechanize::click('WWW::Mechanize=HASH(0x8181abc)') called
at ./reserve.pl line 30

Can anyone tell me what's going on?  I'm running Perl 5.6.1 on Red Hat
Linux 7.3.
0
Reply nospam_timur (23) 9/14/2003 8:01:05 PM

Timur Tabi wrote:

>A friend of mine wrote a Perl script that works fine on his machine
>but dies on mine.  I know very little about Perl, so I need help in
>determining the problem. 

Are you behind a fierwall? Do you need to use a proxy? If so, set the
HTTP_PROXY environment variable, format

	http://proxy.pandora.be:8080


-- 
	Bart.
0
Reply Bart 9/20/2003 7:53:31 PM


Bart Lateur <bart.lateur@pandora.be> wrote in message news:<20cpmvgc2esnpcsp502i262v62mhmfmod4@4ax.com>...
> Timur Tabi wrote:
> 
> >A friend of mine wrote a Perl script that works fine on his machine
> >but dies on mine.  I know very little about Perl, so I need help in
> >determining the problem. 
> 
> Are you behind a fierwall? Do you need to use a proxy? If so, set the
> HTTP_PROXY environment variable, format

My friend and I are in the same subnet, and we're not behind a
firewall.  Regardless, neither he nor I have the HTTP_PROXY variable
set.

Besides, I know that can't be the problem.  The WWW::Mechanize get()
command works just fine.  It's the click() command that doesn't work.

BTW, I want to thank you for trying to solve my problem.  All of the
other replies I received were flames because I was trying to ask for
help.  Apparently, I'm not supposed to do that here.
0
Reply nospam_timur 9/22/2003 3:01:36 PM

Timur Tabi wrote:

> The WWW::Mechanize get()
>command works just fine.  It's the click() command that doesn't work.

First off, I will say that I find that WWW::Mechanize is a very hard
module to debug scripts for. Far too hard.

I could be wrong, but this message:

	Unexpected field value

says to me that you don't seem to have a form selected. In other words:
I doubt if there's a form in that page. Try

	$agent->form(1);

before calling field(). See if it complains. If it doesn't, you should
try to get a list of fields that are in that form, though I'm not sure
how you can do that.

I hate that module. Well, some things about it.

-- 
	Bart.
0
Reply Bart 9/22/2003 8:31:41 PM

Bart Lateur <bart.lateur@pandora.be> wrote in message news:<timumvsta2kijo78nnk9tfei2eaqhnsk1o@4ax.com>...

> says to me that you don't seem to have a form selected. In other words:
> I doubt if there's a form in that page. Try
> 
> 	$agent->form(1);
> 
> before calling field(). See if it complains. If it doesn't, you should
> try to get a list of fields that are in that form, though I'm not sure
> how you can do that.

Thanks for the idea.  Unfortunately, it didn't help:

Unexpected field value
http://w3.reserve.ibm.com/Reserve/ReserveLogon-3.htm at
/usr/lib/perl5/vendor_perl/5.6.1/HTTP/Headers.pm line 256
        HTTP::Headers::_header('HTTP::Headers=HASH(0x846bbb0)',
'Referer', 'http://w3.reserve.ibm.com/Reserve/ReserveLogon-3.htm')
called at /usr/lib/perl5/vendor_perl/5.6.1/HTTP/Headers.pm line 150
        HTTP::Headers::header('HTTP::Headers=HASH(0x846bbb0)') called
at (eval 15) line 1
        HTTP::Message::__ANON__('HTTP::Request=HASH(0x846bb50)',
'Referer', 'http://w3.reserve.ibm.com/Reserve/ReserveLogon-3.htm')
called at /usr/lib/perl5/site_perl/5.6.1/WWW/Mechanize.pm line 1045
        WWW::Mechanize::request('WWW::Mechanize=HASH(0x812feb8)',
'HTTP::Request=HASH(0x846bb50)') called at
/usr/lib/perl5/site_perl/5.6.1/WWW/Mechanize.pm line 515
        WWW::Mechanize::click('WWW::Mechanize=HASH(0x812feb8)') called
at /root/bin/reserve.pl line 30

Here's the code in Headers.pm:

    if (defined($val)) {
        my @new = ($op eq 'PUSH') ? @old : ();
        if (!ref($val)) {
            push(@new, $val);
        } elsif (ref($val) eq 'ARRAY') {
            push(@new, @$val);
        } else {
            Carp::croak("Unexpected field value $val");   [line 256]
        }
        $self->{$lc_field} = @new > 1 ? \@new : $new[0];
    }

I tried adding the line "print $val" to see what $val was, but that
just caused a whole bunch of errors in other parts of Headers.pm,
which completely confused me.
0
Reply nospam_timur 9/23/2003 2:47:46 PM

4 Replies
31 Views

(page loaded in 0.107 seconds)


Reply: