Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re: Error 500 in LWP

by hippo (Bishop)
on Aug 17, 2017 at 10:53 UTC ( [id://1197547]=note: print w/replies, xml ) Need Help??


in reply to Error 500 in LWP

Interestingly, bing is the one which fails for me:

$ cat ssl.t use strict; use warnings; use Test::More; use LWP::UserAgent; my @hostnames = ( 'google.com', 'microsoft.com', 'bing.com' ); plan tests => 1 + scalar @hostnames; cmp_ok ($LWP::UserAgent::VERSION, '>=', 6.04, 'LWP is at least fairly +recent'); my $ua = LWP::UserAgent->new; for my $host (@hostnames) { my $res = $ua->head ("https://$host/"); is ($res->code, '200', "$host returns 200") } $ prove -v ssl.t ssl.t .. 1..4 ok 1 - LWP is at least fairly recent ok 2 - google.com returns 200 ok 3 - microsoft.com returns 200 not ok 4 - bing.com returns 200 # Failed test 'bing.com returns 200' # at ssl.t line 19. # got: '405' # expected: '200' # Looks like you failed 1 test of 4. Dubious, test returned 1 (wstat 256, 0x100) Failed 1/4 subtests Test Summary Report ------------------- ssl.t (Wstat: 256 Tests: 4 Failed: 1) Failed test: 4 Non-zero exit status: 1 Files=1, Tests=4, 2 wallclock secs ( 0.04 usr 0.02 sys + 0.33 cusr + 0.02 csys = 0.41 CPU) Result: FAIL

405 is "Method Not Allowed" so bing is just disallowing HEAD requests. I am unable to reproduce your errors and am interested to see your code which works in successfully retrieving a response to a HEAD from bing.com.

Addendum: here are the relevant version numbers:

  • Perl: 5.16.3
  • LWP: 6.15
  • IO::Socket::SSL: 2.012
  • Mozilla::CA: 20141217

Replies are listed 'Best First'.
Re^2: Error 500 in LWP
by YarNik (Sexton) on Aug 17, 2017 at 12:11 UTC
    You're right. My code returns 500,500,405 for Bing. But if I change code:
    use strict; use warnings; use LWP::UserAgent; my @hostnames = ( 'google.com', 'microsoft.com', 'bing.com' ); my $ua = LWP::UserAgent->new; for my $host (@hostnames) { # my $res = $ua->head ("https://$host/"); my $res = $ua->get ("http://$host/"); print $res->code . "\n"; }
    it returns: 200,500,200
    • CentOS release 6.9 (Final)
    • This is perl, v5.10.1 (*) built for i386-linux-thread-multi
    • 5.833 - LWP
    • none
    • none
      500 Can not connect to domen: 443 (connect: Network is unreachable); Client-Warning: Internal response

      Your requests never go outside of your local network if at all. Maybe you need to use a proxy like your browser does, or you have two routes and the name resolution ping-pongs between a working network route and some other network route.

      Maybe the name resolution itself is wonky for some domain names.

      When I make the same 2 changes which you make (https to http and head to get) then all my tests pass. If you are unable to make an HTTP connection to http://microsoft.com/ then that has to be a question for your local network administrator.

        Thanks for all, I am go to the administrator ;)
        With the local network all right, the command is executed and save file. But script LWP with error, there dump:
        # perl ssl.pl $VAR1 = bless( { '_content' => '500 Can\'t connect to www.microsoft.c +om:443 (connect: Network is unreachable) ', '_rc' => 500, '_headers' => bless( { 'client-warning' => 'Internal + response', 'client-date' => 'Fri, 18 Aug + 2017 08:51:50 GMT', 'content-type' => 'text/plain +' }, 'HTTP::Headers' ), '_msg' => 'Can\'t connect to www.microsoft.com:443 ( +connect: Network is unreachable)', '_request' => bless( { '_content' => '', '_uri' => bless( do{\(my $o = + 'https://www.microsoft.com/uk-ua/')}, 'URI::https' ), '_headers' => bless( { 'user-agent' => 'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit +/537.36 (KHTML, like Gecko) Chrome/60.0.3112.90 Safari/537.36' }, 'HTTP +::Headers' ), '_method' => 'GET' }, 'HTTP::Request' ) }, 'HTTP::Response' );

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1197547]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others browsing the Monastery: (6)
As of 2024-04-23 21:06 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found