WWW :: Mechanize突然看不到https网页

时间:2013-05-15 18:17:36

标签: perl ssl

我有一个perl脚本,它使用WWW :: Mechanize打开到我们的单点登录页面的SSL连接,以测试Nagios的连接。昨天,那个剧本停止了工作,我不明白为什么。以下是该脚本调试的片段:

main::(./check_profiles.pl:13): $auth_url    = "https://account.example.com/SSO/index.html";
main::(./check_profiles.pl:14): $profile_url = "https://example.com/prof";
main::(./check_profiles.pl:16): $user = "nagios\@heyyou.com";
main::(./check_profiles.pl:17): $pass = "testing123";
main::(./check_profiles.pl:18): $expected_string = "Bunnies";
main::(./check_profiles.pl:21): $digest_username = "user";
main::(./check_profiles.pl:22): $digest_password = "pass";
main::(./check_profiles.pl:25): $mech = WWW::Mechanize->new( agent=>"Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.4) Gecko/2008102920 Firefox/3.0.4" );
main::(./check_profiles.pl:28): $mech->credentials("example.com/prof:443","Nokia", $digest_username=>$digest_password);
main::(./check_profiles.pl:31): $mech->add_handler("request_send",  sub { shift->dump; return });
main::(./check_profiles.pl:32): $mech->add_handler("response_done", sub { shift->dump; return });
main::(./check_profiles.pl:35): $mech->get( $auth_url );
GET https://account.example.com/SSO/index.html
Accept-Encoding: gzip
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.4) Gecko/2008102920 Firefox/3.0.4

(no content)
500 Can't connect to account.example.com:443 (connect: Network is unreachable)
Content-Type: text/plain
Client-Date: Wed, 15 May 2013 16:16:25 GMT
Client-Warning: Internal response

500 Can't connect to account.example.com:443 (connect: Network is unreachable)\n
Error GETing https://account.example.com/SSO/index.html: Can't connect to account.example.com:443 (connect: Network is unreachable) at ./check_profiles.pl line 35
 at /usr/share/perl5/vendor_perl/WWW/Mechanize.pm line 2747
        WWW::Mechanize::_die('Error ', 'GET', 'ing ', 'URI::https=SCALAR(0x3291d40)', ': ', 'Can\'t connect to account.example.com:443 (connect: Network is ...') called at /usr/share/perl5/vendor_perl/WWW/Mechanize.pm line 2734
        WWW::Mechanize::die('WWW::Mechanize=HASH(0x31ce490)', 'Error ', 'GET', 'ing ', 'URI::https=SCALAR(0x3291d40)', ': ', 'Can\'t connect to account.example.com:443 (connect: Network is ...') called at /usr/share/perl5/vendor_perl/WWW/Mechanize.pm line 2383
        WWW::Mechanize::_update_page('WWW::Mechanize=HASH(0x31ce490)', 'HTTP::Request=HASH(0x330f490)', 'HTTP::Response=HASH(0x3489c28)') called at /usr/share/perl5/vendor_perl/WWW/Mechanize.pm line 2213
        WWW::Mechanize::request('WWW::Mechanize=HASH(0x31ce490)', 'HTTP::Request=HASH(0x330f490)') called at /usr/share/perl5/LWP/UserAgent.pm line 387
        LWP::UserAgent::get('WWW::Mechanize=HASH(0x31ce490)', 'https://account.example.com/SSO/index.html') called at /usr/share/perl5/vendor_perl/WWW/Mechanize.pm line 407
        WWW::Mechanize::get('WWW::Mechanize=HASH(0x31ce490)', 'https://account.example.com/SSO/index.html') called at ./check_profiles.pl line 35

正如您所看到的,WWW :: Mechanize认为没有443访问account.example.com,但事实并非如此。如果是真的,我的整个应用程序都会破坏,并且它运行正常。这进一步证明了这一点:

> telnet account.example.com 443
Trying 2.2.2.2...
Connected to account.example.com.
Escape character is '^]'.

我不知道为什么会这样。任何人都可以根据调试信息确定问题,还是提供任何进一步的帮助?谢谢!

2 个答案:

答案 0 :(得分:1)

WWW :: Mechanize是1.66-1 升级到1.72-1,问题消失了。

答案 1 :(得分:0)

由于'haxor'“用户代理”字符串,他们很可能会踢你。在得到之前你会发生这样的事情:

my $initial_user_agent = 'Mozilla/5.0 (Linux; U; Android 2.2; de-de; HTC Desire HD 1.18.161.2 Build/FRF91) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1';
my $mech = WWW::Mechanize->new( agent => $initial_user_agent );