Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW

Comment on

( #3333=superdoc: print w/replies, xml ) Need Help??


I am getting a 'Network Unreachable' error while trying to download via YouTube API to my server. I use a subroutine

sub getWebContent{ my $url = shift; my $key = shift; return unless $url; my $ua = LWP::UserAgent->new; $ua->agent("Mozilla/5.0 (Windows NT 6.1; rv:12.0) Gecko/2012040321 +1507 Firefox/12.0"); my $req = HTTP::Request->new(GET => $url); $req->content_type('application/x-www-form-urlencoded'); $ua->ssl_opts('verify_hostname' => 0); if($key){ $req->authorization_basic($key, $key); } print "<pre>".$ua->request($req)->as_string."</pre>"; my $res = $ua->request($req); if ($res->is_success) { return $res->content; } else { print $res->status_line, "<br>$url\n<br>\n$key\n<br>\n \n"; return; } }

I get

500 Can't connect to (Network is unreachable)
Content-Type: text/plain
Client-Date: Wed, 05 Dec 2012 02:51:52 GMT
Client-Warning: Internal response

Can't connect to (Network is unreachable)

LWP::Protocol::https::Socket: connect: Network is unreachable at /usr/local/share/perl5/LWP/Protocol/ line 51.

I tried multiple options available in the Monastery and many other forums and failed.

Please Help!

UPDATE: 1. When I use CURL or wget, I could download the data from YouTube. The Problem is with YouTube API only. It works fine with Bing. Youtube sends me the Certificate issued to multiple hosts on Google.

UPDATE : Fixed by force install LWP::Protocol::https::Socket Thanks to all.


In reply to LWP Error '500 Can't connect to (Network is unreachable)' by vcTheGuru

Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?

    What's my password?
    Create A New User
    and all is quiet...

    How do I use this? | Other CB clients
    Other Users?
    Others having an uproarious good time at the Monastery: (6)
    As of 2017-11-20 13:48 GMT
    Find Nodes?
      Voting Booth?
      In order to be able to say "I know Perl", you must have:

      Results (286 votes). Check out past polls.