Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Comment on

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

I am having a very strange problem. I have a script which uses LWP::UserAgent to connect to web pages. It has functioned properly for quite some time, but started failing last week, and LWP::UserAgent reports a 500 error. From this node, I learned that a 500 error does not necessarily come from the server, and that LWP will report 500 even if it does not reach the server. Following a great suggestion I got from this node, I Data::Dumpered the value returned by $ua->request(), discovering that I am getting the message:

Can't connect to <domain>:80 (Bad Hostname '<domain>')

This only happens when the code is run as a CGI.
It works properly from command line, whether as root or the apache user. This script is on several servers, and is functioning properly on one of them, failing on most. I have compared the code between the working server and the rest, and found no differences. LWP::UserAgent is the same on both (2.003) and so is HTTP::Request (1.30). Both machines are running FreeBSD 4.8, and /etc/resolv.conf is the same for both. Our sysadmins made no recent changes to these servers.

Update: Using an IP address instead of the domain name works. Also, forgot to mention that from command line, I can ping and ssh to other domains. Also, mod_perl is involved here.

The code does not seem to be the issue here, but I here is the relevant snippet anyway (not mine):
my $qurl = 'legitmate url (tested -- fails for many)'; my $uasnd = new HTTP::Request ('GET', $qurl); $uasnd->header('Accept' => 'text/html'); my $res = $ua->request($uasnd); use Data::Dumper; print STDERR "RES: ".Dumper( $res )."\n"; my $code= $res->code; # RETURNS 500 my $content= $res->content; # NADA
Output is:
RES: $VAR1 = bless( { '_content' => '', '_rc' => 500, '_headers' => bless( { 'client-date' => 'Wed, 03 Mar 2004 17: +37:09 GMT' }, 'HTTP::Headers' ), '_msg' => 'Can\'t connect to domainname.net:80 (Bad hostname \ +'domainname.net\')', '_request' => bless( { '_content' => '', '_uri' => bless( do{\(my $o = 'http:// +domainname.net/?param1=1&param2=2')}, 'URI::http' ), '_headers' => bless( { 'user-agent' => +'libwww-perl/5.69', 'accept' => 'tex +t/html' }, 'HTTP::Headers +' ), '_method' => 'GET' }, 'HTTP::Request' ) }, 'HTTP::Response' );
Something tells me this is going to be something stupid that I have forgotten, but I have asked several others about this. Anyone had a similar experience or know what this could be? As always, your time and assistance is much appreciated.

bassplayer


In reply to LWP::UserAgent connection problem as CGI by bassplayer

Title:
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!
  • 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
  • Outside of code tags, you may need to use entities for some characters:
            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?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others making s'mores by the fire in the courtyard of the Monastery: (12)
    As of 2014-09-02 20:04 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      My favorite cookbook is:










      Results (29 votes), past polls