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¶m2=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.