Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

WWW::Mechanize and SSL

by Jonathan (Curate)
on Aug 10, 2022 at 13:09 UTC ( #11146076=perlquestion: print w/replies, xml ) Need Help??

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

Firstly, apologies as this is more a SSL issue than just Perl. I have an HTTPS url that I want to pull some data from (the url is another server on our local network). The url works fine with Chrome, MS Edge etc but I'm getting a certificate error running my test script from a dev server (Ubuntu). Also wget also fails with certificate errors.

#!/usr/bin/perl use strict; use warnings; use WWW::Mechanize; use Net::SSLeay; my $m = WWW::Mechanize->new( autocheck => 1 ); print "LWP: $LWP::UserAgent::VERSION\n"; print "Mech: $WWW::Mechanize::VERSION\n"; print "Net::SSLeay $Net::SSLeay::VERSION\n"; my $url = $ARGV[0]; $m->get($url); print $m->content();
Which outputs;
$ ./testit.pl LWP: 6.43 Mech: 1.96 Net::SSLeay 1.88 Error GETing https://xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx: Can't conn +ect to xxxxxxxxxxx:443 (certificate verify failed) at ./testit.pl lin +e 15. $
I suspect there is something available on the companies servers that satisfies browsers but isn't available elsewhere. Anyone seen this before and have any idea what I need to do? Thanks

Replies are listed 'Best First'.
Re: WWW::Mechanize and SSL
by hippo (Bishop) on Aug 10, 2022 at 13:31 UTC
Re: WWW::Mechanize and SSL
by Corion (Patriarch) on Aug 10, 2022 at 13:41 UTC
    certificate verify failed

    This means that whatever website you're accessing is serving a SSL certificate that is not stored in the certificate store of Perl (see Mozilla::CA).

    The two approaches are to either install the appropriate SSL certificate (ask your administrator) and , or to force WWW::Mechanize (and LWP::UserAgent)

    Maybe the following works:

    $ua = WWW::Mechanize->new( ssl_opts => { SSL_ca_path => '/etc/ssl/file-with-company-certificates' +, verify_hostname => 1, } );

    The other is to switch off the SSL host verification:

    <p>Maybe the following works:</p> <c> $ua = WWW::Mechanize->new( ssl_opts => { verify_hostname => 0, } );
Re: WWW::Mechanize and SSL
by Jonathan (Curate) on Aug 11, 2022 at 12:43 UTC
    Thanks guys, You've pointed me in the right direction and it's now working, the problem was that I had to install the companies local root certificate then run update-ca-certificates

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (4)
As of 2022-10-07 10:06 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My preferred way to holiday/vacation is:











    Results (29 votes). Check out past polls.

    Notices?