6

I have a script which is used to get content from Google. It work very well, but now it doesn't. I found a post on stackexchange and I upgrade the library version, but it still doesn't work: I cannot Connect to any HTTPS site using LWP::UserAgent

I have connectivity from the linux machine (telnet googleapis.com 443 works very well).

#!/usr/bin/perl


use CGI 'param';
use CGI::Carp 'fatalsToBrowser';
use DBI;
    require LWP::UserAgent;
    use LWP::Protocol::https;
    use URI::Escape;
    $ENV{PERL_LWP_SSL_VERIFY_HOSTNAME} = 0;
    $access_token='xxx';
    print "LWP::UserAgent: ".LWP::UserAgent->VERSION,"\n";
    print "LWP::Protocol::https: ".LWP::Protocol::https->VERSION,"\n";
    $url="https://www.googleapis.com/oauth2/v1/userinfo?access_token=$access_token";
        my $ua = LWP::UserAgent->new(ssl_opts => { verify_hostname => 0 });
$ua->agent('Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/35.0.1916.153 Safari/537.36');
        $ua->timeout(10);
        $ua->env_proxy;
        my $response = $ua->get("$url");
        if ($response->is_success) {
        print "Am adus cu succes contul de la google";
            $text=$response->decoded_content;  # or whatever
        }
        else {
            print "Response error:".$response->status_line."\n";

        }


1;

The error: 500 Can't connect to www.googleapis.com:443

Any idea why this is suddenly happen?

Community
  • 1
  • 1
Adrian
  • 149
  • 2
  • 6
  • I forgot to mention, that I have LWP::UserAgent 6.06 and LWP::Protocol::https 6.06 – Adrian Nov 27 '14 at 11:49
  • 1
    "It still doesn't work" is a terrible description of your problem. Exactly what unexpected behaviour are you seeing? Are there any error messages? – Dave Cross Nov 27 '14 at 11:58
  • 4
    Please call your script with `perl -MIO::Socket::SSL=debug4` to enable SSL debugging and add the output here. Also, ssl_verify_hostname only cares about verification of the name against the certificate, not about the verification of certificate against trusted CA. That would be `SSL_verify_mode`. – Steffen Ullrich Nov 27 '14 at 12:57
  • I receive the following error from LWP: 500 Can't connect to www.googleapis.com:443. I run the script with MIO::Socket::SSL=debug4, but no additional output.I also had a tcpdump, but the request is not fired outside Perl. – Adrian Nov 27 '14 at 14:59
  • Then you can not connect. There is a firewall in between or you need ad proxy or something like this. – Steffen Ullrich Nov 27 '14 at 17:02
  • 1
    I found the problem. Due to an OS update I need to force SSL_version => 'SSLv3' – Adrian Nov 27 '14 at 18:12

2 Answers2

2

You need to install LWP::Protocol::https using CPAN or by package name perl-LWP-Protocol-https.

What worked for me, is installing it by package name on CentOS by running as root
yum install perl-LWP-Protocol-https

After that https links are opened as they should, with out an empty response.

Ilia Ross
  • 13,086
  • 11
  • 53
  • 88
1

In some cases, you need to force SSLv3

my $ua = LWP::UserAgent->new(ssl_opts => { verify_hostname => 0, SSL_version => 'SSLv3' });
Adrian
  • 149
  • 2
  • 6