LWP Package issue in my script..

Discussion in 'Perl Misc' started by schimata@gmail.com, Mar 7, 2007.

  1. Guest

    Hi guys,

    I ahve the following code:

    ++++++++++++++++++++++++

    use Cwd;
    use XML::parser;
    use LWP::Simple;
    use HTTP::Status;
    use LWP::UserAgent;

    blah..blah..

    blah..


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


    $ua->timeout(1000);
    $ua->env_proxy;
    # $ua->credentials( 'tracker:80', 'tracker', 'hello' => 'abcd@123' );

    my $url ='http://tracker/cfdocs/proddev/admin/ws/api/
    get_all_subfeatures.cfm';
    print "hello";
    my $response = $ua->get($url);

    +++++++++++++++++++++++++++++++

    Now when I run this script, I get the following error:
    ++++++++++++++++++++++++++++++++++++++++++++++++++++
    Can't locate object method "get" via package "LWP::UserAgent" at C:\cq
    \featurexml.pl line 37.
    ++++++++++++++++++++++++++++++++++++++++++++++++++++

    I think that it is the issue with the LWP stuff here. I see the below
    versions of perl and LWP:
    ++++++++++++++++++++++++++++++++++++++
    C:\cq>perl -v
    This is perl, v5.6.0 built for MSWin32-x86-multi-thread
    (with 1 registered patch, see perl -V for more detail)
    Copyright 1987-2000, Larry Wall
    Binary build 623 provided by ActiveState Tool Corp. http://www.ActiveState.com
    Built 16:27:07 Dec 15 2000


    C:\cq>perl -MLWP -e "print $LWP::VERSION"
    5.48
    +++++++++++++++++++++++++++++++++++++++

    Do I need to re-compile LWP pachage? Any pointers here?

    Thanks,
    Srini
    , Mar 7, 2007
    #1
    1. Advertising

  2. Uri Guttman Guest

    >>>>> "s" == schimata <> writes:

    s> use LWP::Simple;
    s> use HTTP::Status;
    s> use LWP::UserAgent;

    you don't need all three of those. LWP::Simple will load LWP::UserAgent
    which will load HTTP::Status. and by loading all those you are confusing
    yourself below.

    s> blah..blah..
    s> blah..

    that isn't valid perl code! :)

    s> my $ua = LWP::UserAgent->new;

    so you are using the OO style with that module. read ITS docs on what
    methods it supports.

    s> $ua->timeout(1000);
    s> $ua->env_proxy;

    those are legit methods for that object.

    s> my $url ='http://tracker/cfdocs/proddev/admin/ws/api/
    s> get_all_subfeatures.cfm';

    be careful when pasting in emails. that line wrapped and shouldn't have
    and if someone cut/pasted it, it would likely fail because of the
    newline in the url.

    s> print "hello";
    s> my $response = $ua->get($url);

    ahh. is get() a method documented in LWP::UserAgent? no it isn't. it is
    an exported sub in LWP::Simple which wraps code around its own $ua. so
    you either call get() as a sub or use $ua and its methods. you can't
    mix/match them.

    uri

    --
    Uri Guttman ------ -------- http://www.stemsystems.com
    --Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
    Search or Offer Perl Jobs ---------------------------- http://jobs.perl.org
    Uri Guttman, Mar 7, 2007
    #2
    1. Advertising

  3. Uri Guttman <> wrote:
    >>>>>> "s" == schimata <> writes:


    > s> blah..blah..
    > s> blah..
    >
    > that isn't valid perl code! :)



    He just has a few too many dots.

    blah..blah.
    blah

    There, that's better.


    --
    Tad McClellan SGML consulting
    Perl programming
    Fort Worth, Texas
    Tad McClellan, Mar 8, 2007
    #3
  4. Mumia W. Guest

    On 03/07/2007 01:29 PM, Uri Guttman wrote:
    >>>>>> "s" == schimata <> writes:

    >
    > s> use LWP::Simple;
    > s> use HTTP::Status;
    > s> use LWP::UserAgent;
    >
    > you don't need all three of those. LWP::Simple will load LWP::UserAgent
    > which will load HTTP::Status. and by loading all those you are confusing
    > yourself below.
    >
    > s> blah..blah..
    > s> blah..
    >
    > that isn't valid perl code! :)
    >
    > s> my $ua = LWP::UserAgent->new;
    >
    > so you are using the OO style with that module. read ITS docs on what
    > methods it supports.
    >
    > s> $ua->timeout(1000);
    > s> $ua->env_proxy;
    >
    > those are legit methods for that object.
    >
    > s> my $url ='http://tracker/cfdocs/proddev/admin/ws/api/
    > s> get_all_subfeatures.cfm';
    >
    > be careful when pasting in emails. that line wrapped and shouldn't have
    > and if someone cut/pasted it, it would likely fail because of the
    > newline in the url.
    >
    > s> print "hello";
    > s> my $response = $ua->get($url);
    >
    > ahh. is get() a method documented in LWP::UserAgent? no it isn't.


    The method is there. I am able to run Schimata's program after changing
    the URL. Evidently, the program Schimata posted is not the one with the
    problem.

    > it is
    > an exported sub in LWP::Simple which wraps code around its own $ua. so
    > you either call get() as a sub or use $ua and its methods. you can't
    > mix/match them.
    >
    > uri
    >


    You are correct though in that using both LWP::Simple and LWP::UserAgent
    is redundant.
    Mumia W., Mar 8, 2007
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. T W Hu

    lwp package head question

    T W Hu, Aug 16, 2005, in forum: Perl Misc
    Replies:
    3
    Views:
    87
    T W Hu
    Aug 16, 2005
  2. Replies:
    3
    Views:
    139
    Ted Zlatanov
    Jan 2, 2007
  3. tommo_blade

    Perl LWP Issue with JSP's

    tommo_blade, Apr 16, 2008, in forum: Perl Misc
    Replies:
    1
    Views:
    167
    tommo_blade
    Apr 16, 2008
  4. Jason Carlton

    Faster way to get PHP script than LWP::Simple

    Jason Carlton, Nov 29, 2009, in forum: Perl Misc
    Replies:
    2
    Views:
    170
    Peter J. Holzer
    Nov 29, 2009
  5. David Karr
    Replies:
    9
    Views:
    874
    David Karr
    Aug 25, 2011
Loading...

Share This Page