Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

LWP dies calling request method

by impossiblerobot (Deacon)
on Aug 03, 2002 at 18:43 UTC ( [id://187371]=perlquestion: print w/replies, xml ) Need Help??

impossiblerobot has asked for the wisdom of the Perl Monks concerning the following question:

Being completely flustered, I once again turn to the Monastery for help:

I am using LWP::UserAgent to post to a couple of secure servers. When I post to the test server, everything works just fine. When I post to the production server, the script dies with the following error:

Can't call method "request" on an undefined value at /usr/lib/perl5/si +te_perl/5.6.0/LWP/UserAgent.pm line 362.

(It appears that the useragent object is somehow disappearing.) The only difference between the two runs is the URL. I've tried running the same script from another server with the same versions of LWP, HTTP::Request, etc., and both passes seem to work right. The code I am running is very simple:

#!/usr/bin/perl -w use strict; use CGI::Carp qw( fatalsToBrowser ); require LWP::UserAgent; use HTTP::Request; use HTTP::Headers; print "Content-type: text/html\n\n"; my $ua = new LWP::UserAgent; my $content = 'Content'; my $URL = 'https://some.address.here'; my $headers = HTTP::Headers->new( MIME_version => '1.0', Content_type => 'application/PTI9', Content_length => length($content), Content_transfer_encoding => 'text', Request_number => 1, Document_type => 'Request', ); print <<"EOH"; <html> <head><title>LWP Test</title></head> <body> <h2>Request</h2> <pre> EOH my $request = HTTP::Request->new(POST => $URL, $headers, $content); print $request->as_string(); print <<"EOH"; </pre> <h2>Response</h2> <pre> EOH my $response = $ua->request($request); if ($response->is_success) { print $response->content; } else { print $response->error_as_HTML; } print <<"EOH"; </pre><h2>Completed</h2> </body></html> EOH exit;

and here are the results of an LWP::Debug trace from the failed attempt(s):

LWP::UserAgent::new: () LWP::UserAgent::request: () LWP::UserAgent::send_request: POST https://some.adddress.here LWP::UserAgent::_need_proxy: Not proxied LWP::Protocol::http::request: () Can't call method "request" on an undefined value at /usr/lib/perl5/si +te_perl/5.6.0/LWP/UserAgent.pm line 362.

I've searched the Monastery and Google, but haven't found a solution. I would appreciate any help my fellow monks can give.


Impossible Robot

Replies are listed 'Best First'.
Re: LWP dies calling request method
by tstock (Curate) on Aug 03, 2002 at 19:18 UTC
    Are you also doing SSL to the test server ? If not, then check if you have SSLeay and everything required to do SSL (https).

    If you where already doing SSL correctly to the test server, then I would check the obvious first. Is the target URL correct and can you reach it from the server you are running the script from ? Can you reach it using lynx, wget or any other client available on that box ?

    Tiago

      Thanks, tstock. I'm using SSL on both servers, so I know that SSL is working.

      I'm also confident of the URL. However, even if the URL were non-existent, LWP should return an error response, not die unexpectedly.


      Impossible Robot
Re: LWP dies calling request method
by valdez (Monsignor) on Aug 03, 2002 at 20:56 UTC

    I tried your script and it works here. So your problem may resides in some module you used. Here I am using:

    • Perl 5.6.0
    • OpenSSL 0.9.6
    • Net_SSLeay.pm v1.18 Crypt-SSLeay v0.37
    • Net::HTTPS v 1.2
    • LWP::UserAgent v 2.1

    Probably I'm not using the newest modules, but I hope these information can help you figure out what happened.

    Ciao, Valerio

    update: changed used modules
Re: LWP dies calling request method
by insensate (Hermit) on Aug 03, 2002 at 21:51 UTC
    I would try including a module like Crypt::SSLeay. That's my suggestion after reading this. Also, I know that oftentimes test servers have weaker certificates than production servers...perhaps your script is choking on a 1024 bit certificate from the prod site and can manage a 512 bit certificate.

    Best,
    Jason

      Thanks, insensate. It looks like my copy of Crypt::SSLeay may have been the culprit. I've upgraded, and so far my tests appear to be successful.


      Impossible Robot

      He must already have Crypt::SSleay, otherwise he would get unsupported protocol error from LWP.

      Ciao, Valerio

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://187371]
Approved by Zaxo
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others examining the Monastery: (4)
As of 2024-04-20 09:11 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found