|laziness, impatience, and hubris|
LWP::UserAgent connection problem as CGIby bassplayer (Monsignor)
|on Mar 03, 2004 at 17:58 UTC||Need Help??|
bassplayer has asked for the
wisdom of the Perl Monks concerning the following question:
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):
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.