Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > LWP seems to hang

Reply
Thread Tools

LWP seems to hang

 
 
masmith27
Guest
Posts: n/a
 
      08-09-2006
Hello, I have made a very simple script in perl that uses LWP to visit
a few local webpages. The script has to execute without any user
interaction after the computer has finished booting. When the computer
boots up it starts the script and tries to get the first webpage. The
script then seems to hang after making the request, and setting the
timeout has no effect. The strange part is that if I hit any key a few
times the script then gets the webpage and continues normally.
LWP:ebug gives the following:
LWP::UserAgent::new: ()
LWP::UserAgent::request: ()
HTTP::Cookies::add_cookie_header: Checking 127.0.0.1 for cookies
HTTP::Cookies::add_cookie_header: Checking .0.0.1 for cookies
HTTP::Cookies::add_cookie_header: Checking 0.0.1 for cookies
HTTP::Cookies::add_cookie_header: Checking .0.1 for cookies
HTTP::Cookies::add_cookie_header: Checking 0.1 for cookies
HTTP::Cookies::add_cookie_header: Checking .1 for cookies
LWP::UserAgent::send_request: GET https://127.0.0.1:2381/webpage.php
LWP::UserAgent::need_proxy: Not proxied
LWP:rotocol::http::request: ()

and that's where it stops unless I hit a key or two on the keyboard.
This makes me think that for some reason perl is waiting for something
from stdin but there is nothing I can see that would make this the
case. The script works fine after hitting a few keys or after logging
into the system and issuing a command to run the script, but I need it
to run automatically using init.d. Is there a fix for something like
this? Or something I should check? I'm running out of ideas. The
relevant portion of the code is given below.

#!/usr/bin/perl -w

use LWP;
use HTTP::Cookies;

my $browser = LWP::UserAgent->new;

$browser->timeout("15");

$browser->cookie_jar( HTTP::Cookies->new('file' => '/tmp/cookies.lwp',
'autosave' => 1,
));

push @{ $browser->requests_redirectable }, 'POST';

$url = 'https://127.0.0.1:2381/webpage.php
$response = $browser->get($url);
die "Can't get $url -- ", $response->status_line unless
$response->is_success;

 
Reply With Quote
 
 
 
 
John Bokma
Guest
Posts: n/a
 
      08-09-2006
"masmith27" <(E-Mail Removed)> wrote:

> #!/usr/bin/perl -w


remove the -w

add:

use strict;
use warnings;

> use LWP;
> use HTTP::Cookies;
>
> my $browser = LWP::UserAgent->new;
>
> $browser->timeout("15");


15 is a number, why do you use "" ?

> $browser->cookie_jar( HTTP::Cookies->new('file' => '/tmp/cookies.lwp',
> 'autosave' => 1,
> ));


note that the '' around file and autosave are not needed thanks to some
magic => does to the LHS.

> push @{ $browser->requests_redirectable }, 'POST';
>
> $url = 'https://127.0.0.1:2381/webpage.php


my $url = ....

> $response = $browser->get($url);


my $response = ...

> die "Can't get $url -- ", $response->status_line unless
> $response->is_success;


I prefer:

$response->is_success or
die " ...... ";

Which I read as: for the next steps it's important that the response is
successfull, otherwise we die.


The "15" might be the cause of your timeout not working.

Also note that you need support for https installed (Crypt::SSLeay for
example) but I assume you have that installed otherwise LWP would
complain.

--
John Bokma Freelance software developer
&
Experienced Perl programmer: http://castleamber.com/
 
Reply With Quote
 
 
 
 
masmith27
Guest
Posts: n/a
 
      08-10-2006
Hello,
Thanks for the response. I have made the changes you suggested, but
still no change. You have reminded me that I forgot to mention a couple
things in my first post though. When I said the timeout has no response
I meant that including the timeout statement does not change the script
at all, changing the number inside has no change either, 15 was just
the last value I had tried. I also forgot to mention that I have tried
getting this website with SSL enabled and with SSL disabled since the
website does not require SSL but I have left it enabled due to some
details of the project I am working on. SSLeay is also installed.


John Bokma wrote:
> "masmith27" <(E-Mail Removed)> wrote:
>
> > #!/usr/bin/perl -w

>
> remove the -w
>
> add:
>
> use strict;
> use warnings;
>
> > use LWP;
> > use HTTP::Cookies;
> >
> > my $browser = LWP::UserAgent->new;
> >
> > $browser->timeout("15");

>
> 15 is a number, why do you use "" ?
>
> > $browser->cookie_jar( HTTP::Cookies->new('file' => '/tmp/cookies.lwp',
> > 'autosave' => 1,
> > ));

>
> note that the '' around file and autosave are not needed thanks to some
> magic => does to the LHS.
>
> > push @{ $browser->requests_redirectable }, 'POST';
> >
> > $url = 'https://127.0.0.1:2381/webpage.php

>
> my $url = ....
>
> > $response = $browser->get($url);

>
> my $response = ...
>
> > die "Can't get $url -- ", $response->status_line unless
> > $response->is_success;

>
> I prefer:
>
> $response->is_success or
> die " ...... ";
>
> Which I read as: for the next steps it's important that the response is
> successfull, otherwise we die.
>
>
> The "15" might be the cause of your timeout not working.
>
> Also note that you need support for https installed (Crypt::SSLeay for
> example) but I assume you have that installed otherwise LWP would
> complain.
>
> --
> John Bokma Freelance software developer
> &
> Experienced Perl programmer: http://castleamber.com/


 
Reply With Quote
 
J. Gleixner
Guest
Posts: n/a
 
      08-10-2006
masmith27 wrote:

> $url = 'https://127.0.0.1:2381/webpage.php


my $url = 'https://127.0.0.1:2381/webpage.php';

That could have been a typo, which could possibly mean that you're
leaving out other code.
 
Reply With Quote
 
John Bokma
Guest
Posts: n/a
 
      08-10-2006
"masmith27" <(E-Mail Removed)> wrote:

> Hello,
> Thanks for the response. I have made the changes you suggested, but
> still no change. You have reminded me that I forgot to mention a couple
> things in my first post though. When I said the timeout has no response
> I meant that including the timeout statement does not change the script
> at all, changing the number inside has no change either, 15 was just
> the last value I had tried.


I suggested that "15" is not a number, but a string. I couldn't be
bothered to check if LWP is able to use is as a number, but I do recommend
not to quote numbers if you need it as a number.

You might want to try an actual number.


Another huge tip:

http://johnbokma.com/mexit/2006/04/11/how-to-reply.html

It's not finished (the debunking part that is), but I think the recipe is
easy to follow and very sound.


--
John Bokma Freelance software developer
&
Experienced Perl programmer: http://castleamber.com/
 
Reply With Quote
 
masmith27
Guest
Posts: n/a
 
      08-14-2006
Hello again,
After looking at the problem some more I noticed it has nothing to do
with perl or lwp. The same error occurs if I try to use wget to fetch a
webpage. Also the script works fine if the pages are hosted in apache
but unfortunatly I can't use apache for reasons specific to the
project. I should have thought to test that earlier but I didn't think
of it. I have started a new topic in comp.os.linux.misc. Thanks for
the responses with this one though.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
LWP::UserAgent infinite hang Tomek Perl Misc 1 03-06-2007 04:50 AM
Thunderbird Hang up option Gudul Firefox 0 02-14-2005 12:19 AM
A weird problem, computer hang while loading wireless, please help =?Utf-8?B?eHV6aGltbw==?= Wireless Networking 0 12-17-2004 04:45 PM
Socket Hang pjhoust@canada.com Perl 0 08-26-2003 12:55 AM
MELL and Server Hang Issues Chrystal Microsoft Certification 0 08-07-2003 02:18 PM



Advertisments