http://www.perlmonks.org?node_id=1043203

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

Hi Monks,

I am using POP3Client to login to email account and Mechanize to get a weblink. Having problems to have them both working.

The functionality in my script using Mechanize works as expected if either IO::SOCKET::SSL or NET::SSLeay is not installed. However, if I install both IO::SOCKET::SSL and NET::SSLeay, then the Mechanize functionality does not work. Since my script also has functionality that uses POP3Client, I need both IO::SOCKET::SSL and NET::SSLeay.

Any suggestions to have both POP3Client and Mechanize working with both IO::SOCKET::SSL and NET::SSLeay installed?

Here are the details from the script.

my $pop = new Mail::POP3Client( USER => "user_name", PASSWORD => "password", HOST => "mail.xxxxx.com", USESSL => 1, PORT => 995, DEBUG => 0, ); my $num = $pop->Count; if($num < 0) { print "Error could not connect\n"; } elsif ($num == 0){ print "================LOGIN SUCESS!\n"; } my $url = "http://weblink"; my $m; $m = WWW::Mechanize->new(autocheck=>1); $m->proxy('http','http://proxy_server'); $m->proxy('https', undef); $m->credentials( "user_name", "password" ); $m->get($url); #<============ DIES HERE my $link = $m->find_link( text => "A string" ); if( !defined( $link ) ) { print( "Error accessing $url!\n" ); die; }

Thanks,

Madhu

Replies are listed 'Best First'.
Re: IO::Socket::SSL incompatibility with WWW::Mechanize
by syphilis (Archbishop) on Jul 09, 2013 at 01:22 UTC
    Hi Madhu,
    Just for completeness, what's the error you get ?

    Cheers,
    Rob

      Here is the error.

      Error GETing https:weblink : Can't connect to login.xxxxxx.com:443 (connect: Unknown error) at mech_test.pl line xxx.

      Just to give more information. I don't see this problem if I run on a computer that doesn't require to go through the proxy.

      Thanks,

      Madhu

        I don't use WWW::Mechanize, but have a look at its noproxy documentation. It says:

        This needs to be explicitly turned off if you're using Crypt::SSLeay to access a https site via a proxy server. Note: you still need to set your HTTPS_PROXY environment variable as appropriate.

        Even if you're not using Crypt::SSLeay, there might be something (not sure exactly what) of relevance there.

        Cheers,
        Rob
Re: IO::Socket::SSL incompatibility with WWW::Mechanize
by runrig (Abbot) on Jul 11, 2013 at 19:59 UTC
    Mechanize works as expected if either IO::SOCKET::SSL or NET::SSLeay is not installed.

    That makes sense, somewhat, because IO::Socket::SSL requires Net::SSLeay (so you should not be able to install or use the first without the second anyway). Net::HTTPS prefers IO::Socket::SSL over Net::SSL, so if IO::Socket::SSL is completely installed (i.e., with Net::SSLeay), then it will use that library. Otherwise it will use Net::SSL, and that is what is happening if you only have one of those two modules you mention installed.

    Make sure you have the latest version of Net-HTTP because there have been issues with that library when used in combination with IO::Socket::SSL. You can also set $Net::HTTPS::SSL_SOCKET_CLASS or environment variable PERL_NET_HTTPS_SSL_SOCKET_CLASS to 'Net::SSL' to explicitly use that library instead of the other.

      Setting the $Net::HTTPS::SSL_SOCKET_CLASS to 'Net::SSL' helped. Both POP3Client and Mechanize are working as expected now.

      Included the below code in the beginning of the script.

      use Net::SSL (); $Net::HTTPS::SSL_SOCKET_CLASS = "Net::SSL";

      Thank you for the help!

      Madhu

        Do you have the latest Net-HTTP installed? I'm guessing no, because then I think you would have to set environment variable PERL_LWP_SSL_VERIFY_HOSTNAME to 0.