Re: Unable to connect a website using LWP
- From: "harryfmudd [AT] comcast [DOT] net" <"harryfmudd [AT] comcast [DOT] net">
- Date: Thu, 23 Feb 2006 10:37:42 -0500
Paul Lalli wrote:
prasanna_ssb@xxxxxxxxxxxxxx wrote:
Hi,
Iam trying to connect to a website
That's not a website. The world wide web uses the HTTP proticol. This
URL uses the FTP proticol.
Does LWP handle FTP addresses? I have no idea. But it seems like it
shouldn't have any reason to.
Actually, LWP handles FTP as well as HTTP, as
GET ftp://ftp.rcsb.org/pub/pdb/data/structures/all/pdb/
will demonsrate.
Perhaps you should be using the Net::FTP module instead.
Net::FTP will work also. There's More Than One Way To Do It.
to download files
from there. I am using LWP for the same and I am getting the following
Error
Cant get ftp://ftp.rcsb.org/pub/pdb/data/structures/all/pdb/:
HTTP::Response=HASH(0x98ceb34)->status_line at try.pl line 18.
Where can I know what this error code stands for?
You didn't print out the error code. That's at least half your
problem.
Here is the portion of the code referring to this problem
#! /usr/bin/perl
use warnings;
use strict;
use lib '/home/ms2/PERL/LWP/libwww-perl-5.800/lib/';
use LWP;
#Create a UserAgent object
use LWP::UserAgent;
my $ua = LWP::UserAgent->new;
#need to make a get request
my $url = 'ftp://ftp.rcsb.prg/pub/pdb/data/structures/all/pdb/';
Earlier in your post you said you were going for 'ftp.rcsb.org'. If you get your error reporting sorted out, you will find that domain 'ftp.rcsb.prg' does not exist.
my $response = $ua->get($url);
if ($response->is_success == 0 ) { die "Cant get $url:\n
$response->status_line"; }
status_line is a method of the HTTP::Response class. You can not
interpolate method calls in a double quoted string, any more than you
can interpolate function calls.
die "Can't get $url:\n", $response->status_line;
Make that change and see what the error status actually is.
I would like to recommend, in lieu of your two lines, something like
$response->is_success or
die "Can't get $url:\n", $response->status_line, "\n";
The explicit '== 0' probably does what you think it does though, so maybe it's just a matter of style. The previous poster is correct,
though, you can't interpolate a subroutine or method call into a string. At least, not directly. You _can_ do something like
$response->is_success or die <<eod;
Can't get $url:
@{[$response->status_line]}
eod
if you want, using the @{[ ]} idiom to interpolate a list which you build on-the-fly.
Tom Wyant
.
- Follow-Ups:
- Re: Unable to connect a website using LWP
- From: Prasanna
- Re: Unable to connect a website using LWP
- From: Paul Lalli
- Re: Unable to connect a website using LWP
- References:
- Unable to connect a website using LWP
- From: prasanna_ssb
- Re: Unable to connect a website using LWP
- From: Paul Lalli
- Unable to connect a website using LWP
- Prev by Date: CAM::PDF and images
- Next by Date: Re: Unable to connect a website using LWP
- Previous by thread: Re: Unable to connect a website using LWP
- Next by thread: Re: Unable to connect a website using LWP
- Index(es):