Re: Bad hostname
by Sewi (Friar) on Sep 13, 2009 at 08:55 UTC
|
Find a way to get debug messages from your script. This may be print STDERR, a temp log file in /tmp or anything else. Then print the exact URL you use for the LWP call and also the error message from your LWP handle.
You may not call your script at all, you may get wrong parameters because of ', " or $ problems or something else.
You should also print $ENV{http_proxy}, because your script may run in an environment which uses a proxy without your knowledge.
If really everything is fine, try a print logfile `ping -c 1 host.name.com 2>&1`;
| [reply] [d/l] |
|
|
Hi Sewi:
> Find a way to get debug messages
> from your script. This may be
> print STDERR, a temp log file
> in /tmp or anything else.
yes, I already print everything into a log file
> Then print the exact URL you
> use for the LWP call and also
> the error message from your
> LWP handle.
the URL is fine
> You should also print $ENV{http_proxy}
no proxy found
Anycase: the exact message that I get from the KWP user agent is the following:
500 Can't connect to www.sandbox.paypal.com:80 (Bad hostname 'www.sandbox.paypal.com')
And if I add the hostname into /etc/hosts the status line turns to:
500 Can't connect to www.sandbox.paypal.com:80 (Permission denied)
and this latter status line is also given if I change the URL with the corresponding IP:
500 Can't connect to 216.113.191.82:80 (Permission denied)
but this doesn't prove anything because maybe there could be many virtual hosts with the same IP.
Finally, as you are suggesting:
> If really everything is fine, try a
> print logfile `ping -c 1 host.name.com 2>&1`;
I tried to ping the PayPal SandBox without involving LWP, I just pinged it with backticks. This is the returned message:
unknown host www.sandbox.paypal.com
It looks like DNS is not resolved, but only when the script is called by Apache. When the script is called from the command line the DNS is properly resolved, and the script works just fine.
BTW: on another web server, with Fedora 4 instead of Fedora 5, the entire set of scripts work fine even when called by Apache.
Thanks for your help. Alvise.
| [reply] [d/l] [select] |
|
|
BTW: on another web server, with Fedora 4 instead of Fedora 5, the entire set of scripts work fine even when called by Apache.
Does your Fedora 5 box maybe have SELinux enabled? (it could in theory be responsible for such problems)
Try setenforce 0 to (temporarily) disable SELinux for testing purposes...  (see also selinux-faq-fc5)
| [reply] [d/l] |
|
|
|
|
| [reply] |
Re: Bad hostname
by Gangabass (Vicar) on Sep 13, 2009 at 07:30 UTC
|
| [reply] |
|
|
yes, the script has 755 permissions. A.
| [reply] |
Re: Bad hostname
by ikegami (Patriarch) on Sep 14, 2009 at 04:19 UTC
|
LWP doesn't return such messages. Either the message isn't from LWP, or I think you're lying about the message. I presume you were actually getting something of the form
500 Can't connect to $host:$port (Bad hostname '$host')
If the message you are getting is the form
500 Can't connect to $host:$port ($error_cause)
then the error message is originating from the operating system while LWP was attempting to create a connection. If the OS is telling you there's a permission problem, then there's some OS-level security setting preventing you (the web server user) from creating internet connections.
Are you using SELinux? In any case, this isn't a Perl issue.
* — The 500 might be absent depending on how you got the message.
| [reply] [d/l] [select] |
|
|
I agree with you that the format of the typical LWP response is something like you have just stated. But the error message that I am forwarding in my posts is the status_line of the response object, not that of the user agent object.
Far from me the idea of wasting your time (and mine) by faking the messages... I just copied and pasted them.
Anycase I've disabled SELinux and the problem has been solved. But now another problem arises: should I leave SELinux disabled ???
Thanks for taking the time to respond to me. A.
| [reply] |
|
|
the error message that I am forwarding in my posts is the status_line of the response object, not that of the user agent object.
You are mistaken. It's LWP::UserAgent that places the error in the status line (after being generated by LWP::Protocol::http). That is how LWP reports errors.
So yes, we were on the same page. Maybe older versions of LWP had different messages, sorry.
Update: It would have to be a very old version. Older than libwww-perl-5.800, released on June 15th, 2004. That's the earliest version currently on CPAN.
| [reply] |
|
|
lwp-request http://nonsense/
500 Can't connect to nonsense:80 (Bad hostname 'nonsense')
| [reply] [d/l] |
|
|
Repeating me? What's your point?
| [reply] |
Re: Bad hostname
by ambrus (Abbot) on Nov 17, 2009 at 09:58 UTC
|
Could iptables (or some other packet filter) be stopping you from connecting to that host? I think you can get a permission denied message in that case, but I'm not completely sure.
| [reply] |
Re: Bad hostname
by Anonymous Monk on Feb 13, 2012 at 03:54 UTC
|
Whats the Solution for this Bad Host-name issue??
I tried all the solutions mentioned in the thread but none worked with me :(
I am using WWW:Mechanize to access the web addresses. | [reply] |
|
|
Whats the Solution for this Bad Host-name issue?? I tried all the solutions mentioned in the thread but none worked with me :( I am using WWW:Mechanize to access the web addresses.
Please list each solution you tried and how you did it
| [reply] |
Re: Bad hostname
by shawnhcorey (Friar) on Apr 24, 2012 at 14:07 UTC
|
I have a web spider that gets "Bad hostname", that is, sometimes it does and sometimes it doesn't. Since I don't change anything on my computers, it must be a problem on the internet. I think it's because the DNS cannot resolve the name. I have gotten it on two different ISPs, so switch ISPs won't help. I have yet to figure out what it really means. :(
| [reply] |