develooper Front page | perl.libwww | Postings from January 2001

Can't call method "request" on an undefined value at ...

From:
Vern Hart
Date:
January 28, 2001 23:51
Subject:
Can't call method "request" on an undefined value at ...
Message ID:
Pine.GSO.4.21.0101282343570.18651-100000@vax.area.com
Full error:

    Can't call method "request" on an undefined value at
    /usr/lib/perl5/site_perl/5.005/LWP/UserAgent.pm line 227, <DOM>
    chunk 69.

I've got a script that does a couple thousand requests to an https
URL.  I get the above error sporadicly.  I've had it at chunk 69,
640, 234, etc.  It's seemingly random and nothing changes between
runs except the location of the error.

I'm new to the list but noticed, in the archive, someone having a
similar (but more repeatable) problem.
http://www.ics.uci.edu/pub/websoft/libwww-perl/archive/2000h2/0819.html
One similarity is that Robert was using the same protocol, https.

The problem within LWP::UserAgent::simple_request (which gets called
from LWP::UserAgent::request, which I'm using) is that the eval
block at line 211 dies but $@ is not set to anything.  I worked
around the problem by creating a valid response object if $response
was not defined just after the eval block.

It's possible there's a bug in LWP::Protocol::https (since both
Robert and I are using https) but I can't reproduced the error
reliably enough to track it there.

The following patch is probably not a long-term solution but it at
least gives an error response instead of crashing the script.  In my
case, my script handles the false $response->is_success and retries
the request which then works.  YMMV.

Cheers,
Vern


--- LWP/UserAgent.old	Thu Jun  1 07:35:15 2000
+++ LWP/UserAgent.pm	Sun Jan 28 23:26:26 2001
@@ -218,6 +218,12 @@
	      HTTP::Response->new(&HTTP::Status::RC_INTERNAL_SERVER_ERROR,
				  $@);
	}
+	elsif (!defined $response)
+	{
+	    $response =
+	      HTTP::Response->new(&HTTP::Status::RC_INTERNAL_SERVER_ERROR,
+				  "Unknown Error");
+	}
     } else {
	$response = $protocol->request($request, $proxy,
				       $arg, $size, $timeout);





nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About