17

I created a Perl script to run an https task. When I run it I get the error LWP::Protocol::https not installed.

I cannot figure out, or find a tutorial or command on how exactly to install LWP::Protocol::http. Anyone have any idea how to install it? Installing LWP was quite easy.

I have installed LWP and installed Crypt-SSLeay, however I still get the error. Here is my code:

use LWP::UserAgent;

my $ua = LWP::UserAgent->new;


# set custom HTTP request header fields

my $req = HTTP::Request->new(PUT => "https://thesite.com");

$req->header('Authorization' => 'myauth');
$req->header('Accept' => 'JSON:Application/JSON');
$req->header('Content-Type' => 'JSON:Application/JSON');
$req->header('Host' => 'api.thesite.com');

$req->content('Text' => 'thetext');



my $resp = $ua->request($req);
if ($resp->is_success) {
    my $message = $resp->decoded_content;
    print "Received reply: $message\n";
}
else {
    print "HTTP POST error code: ", $resp->code, "\n";
    print "HTTP POST error message: ", $resp->message, "\n";
}
6
  • 4
    If the error tells you LWP::Protocol::https is not installed, install it. Jan 14, 2014 at 20:47
  • Oh geesh. It's been a bad day. I need to edit this question. I got so caught up, I didn't as the right thing...
    – CRAIG
    Jan 14, 2014 at 20:49
  • 5
    cpan then install LWP::Protocol::https or install Bundle::LWP Jan 14, 2014 at 20:51
  • 5
  • 1
    Man, I thought I tried that. Ok, very good. It is installing now. Thanks so much for the quick help!!
    – CRAIG
    Jan 14, 2014 at 20:54

4 Answers 4

23

sudo yum install perl-LWP-Protocol-https fixed issue for me.

12

Running sudo cpan install LWP::Protocol::https fixed this for me.

2
  • 1
    sudo perl -MCPAN -we 'install "LWP::Protocol::https"' didn't worked because some test failed, and your command worked. THANK YOU SO MUCH!
    – yannis
    Feb 17, 2020 at 17:27
  • Note that the "install" in that command is a no-op. Just cpan LWP::Protocol::https is what you need. Oct 11, 2021 at 13:18
1

A long time ago, LWP came with HTTPS support. Then, in 6.02 (in 2011), they unbundled the LWP::Protocol::https. If your program was set up on an ancient system and you are upgraded, this change can trip you up.

Since Perl does not have SSL support out of the box, it didn't make sense to have a protocol helper that was missing what it needs (and remember HTTPS everywhere wasn't quite as prevalent then). As a separate module, it's easier to get everything set up.

Now, here's the trick. LWP::Protocol::https needs IO::Socket::SSL which needs Net::SSLeay which needs openssl. How you install that is up to you, and if your platform has a ready-to-go package, that might be best (because if you know you don't want that, you're unlikely to ask your question).

If you want to do the whole chain yourself, start with openssl. Once that's sorted, you can install the module you need and the rest of the pre-requisites will take care of themselves:

# ... install openssl, set env vars if in a nonstandard location
% cpan LWP::Protocol::https

As a side note, older Perl practices didn't include using all the modules you knew you depended on. In this case, you formerly didn't declare a dependency on LWP::Protocol::https because you knew it came with LWP. Now it's much better to explicitly declare every thing you need even if you know some modules come in the same distribution. Maybe some time in the future they'll be in different distributions.

Although I use Mojo::UserAgent for all this now, I'd add the explicit dependency even though LWP takes care of it all internally. This makes static analysis a bit easier:

use LWP;
use LWP::Protocol::https;
2
0

If you get this error:

Can't locate LWP/Protocol/https.pm in @INC (@INC contains: /etc/cxs /usr/local/lib64/perl5 /usr/local/share/perl5 /usr/lib64/perl5/vendor_perl /usr/share/perl5/vendor_perl /usr/lib64/perl5 /usr/share/perl5 .) at (eval 5) line 2.

You need to install LWP::Protocol::https, using for instance:

cpan LWP::Protocol::https
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.