reading from an url

R

Rajesh

Hi,

I checked the archives and faq in Perl. ostly from the archives, I got
to put up the following code to read from an url. But, if i run this
code i get the error,
500: Can't connect to www.yahoo.com:80 ((Bad hostname www.yahoo.com)

I believe it has something to do with internet connectivity. But, i
can acces the page using Internet explorer. So, do i have to specify
some proxy or something in the program?
Or is something wrong with the script?
P.S... I am running the perl script in Windows XP.

#!/usr/local/bin/perl -w

use LWP::Simple;
use LWP::UserAgent;

$url = "http://www.yahoo.com";

$ua = new LWP::UserAgent;
$ua->agent("$0/0.1");

$req = new HTTP::Request 'HEAD', $url;
$req->header('Accept' => 'text/html');

# send request
$res = $ua->request($req);

# check the outcome
if ($res->is_success) {
print "The link <$url> is ok.\n";
} else {
print "<$url>\n";
print " " . $res->code . " " . $res->message . "\n\n";
}


Rajesh
 
G

Gregory Toomey

It was a dark and stormy night, and Rajesh managed to scribble:
Hi,

I checked the archives and faq in Perl. ostly from the archives, I got
to put up the following code to read from an url. But, if i run this
code i get the error,
500: Can't connect to www.yahoo.com:80 ((Bad hostname www.yahoo.com)

I believe it has something to do with internet connectivity. But, i
can acces the page using Internet explorer. So, do i have to specify
some proxy or something in the program?
Or is something wrong with the script?
P.S... I am running the perl script in Windows XP.

Yahoo has code to stop you doing automatic downloads.


gtoomey
 
T

Tassilo v. Parseval

Also sprach Gregory Toomey:
It was a dark and stormy night, and Rajesh managed to scribble:


Yahoo has code to stop you doing automatic downloads.

But this can't be the explanation here since the OP's snippet works fine
for me and produces

The link <http://www.yahoo.com> is ok.

It must be a network problem. When I bogify the URL to
<http://wwwwwwwwwwwwww.yahoo.com> I get the same message the OP got.

Tassilo
 
J

James Willmore

On 16 Dec 2003 23:36:10 -0800
Hi,

I checked the archives and faq in Perl. ostly from the archives, I
got to put up the following code to read from an url. But, if i run
this code i get the error,
500: Can't connect to www.yahoo.com:80 ((Bad hostname
www.yahoo.com)

Looks like (and I could be wrong) your DNS lookup failed. Possible
causes (on *NIX) is your resolv.conf file is fould or you have no
route to the host (firewall maybe?). No sure what could be going on
if your using WinXP (as stated in the sniped portion of your post). I
think netstat (at the command prompt) will give you routing
information (WinXP is trying to "play nice" with *NIX systems).

All in all, this doesn't appear to be a Perl issue, but an issue with
your system. Check your settings, try connecting with a browser, and
then see if your script works. If all else fails, change the URL in
your script to see if you can connect anywhere at all.

HTH

--
Jim

Copyright notice: all code written by the author in this post is
released under the GPL. http://www.gnu.org/licenses/gpl.txt
for more information.

a fortune quote ...
Mandrell: "You know what I think?" Doctor: "Ah, ah that's a
catch question. With a brain your size you don't think,
right?" -- Dr. Who
 
R

Rajesh

Looks like (and I could be wrong) your DNS lookup failed. Possible
causes (on *NIX) is your resolv.conf file is fould or you have no
route to the host (firewall maybe?). No sure what could be going on
if your using WinXP (as stated in the sniped portion of your post). I
think netstat (at the command prompt) will give you routing
information (WinXP is trying to "play nice" with *NIX systems).

All in all, this doesn't appear to be a Perl issue, but an issue with
your system. Check your settings, try connecting with a browser, and
then see if your script works. If all else fails, change the URL in
your script to see if you can connect anywhere at all.


Thanks Jim. I think its because of a firewall. But, why is firewall
preventing me from reading an url? Browsers work fine and the same url
opens in a browser and the script fails for all the urls.
 
C

Carsten Aulbert

Rajesh said:
Thanks Jim. I think its because of a firewall. But, why is firewall
preventing me from reading an url? Browsers work fine and the same url
opens in a browser and the script fails for all the urls.

Question: Have you installed a personal firewall and decided in the
beginning that the "process" Internet Explorer may connect to the outside
world and you forgot to enable perl to connect to the outside world?

Just guessing since I don't use personal firewalls and Windows on the net.

CA
 
B

Bryan Castillo

Hi,

I checked the archives and faq in Perl. ostly from the archives, I got
to put up the following code to read from an url. But, if i run this
code i get the error,
500: Can't connect to www.yahoo.com:80 ((Bad hostname www.yahoo.com)

I believe it has something to do with internet connectivity. But, i
can acces the page using Internet explorer. So, do i have to specify
some proxy or something in the program?
^^^^^

Do you have a proxy configured in IE?
If so you might try setting the proxy.

From LWP::UserAgent docs


$ua->proxy(...)
Set/retrieve proxy URL for a scheme:

$ua->proxy(['http', 'ftp'], 'http://proxy.sn.no:8001/');
$ua->proxy('gopher', 'http://proxy.sn.no:8001/');

The first form specifies that the URL is to be used for proxying
of access methods listed in the list in the first method argument,
i.e. 'http' and 'ftp'.

The second form shows a shorthand form for specifying proxy URL
for a single access scheme.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

Forum statistics

Threads
474,143
Messages
2,570,822
Members
47,368
Latest member
michaelsmithh

Latest Threads

Top