in reply to Re^2: Can't call method "extract_cookies" on an undefined value
in thread Can't call method "extract_cookies" on an undefined value

"extract_cookies" comes from: http://search.cpan.org/~gaas/HTTP-Cookies-6.01/lib/HTTP/Cookies.pm

You will see that the synopsis on that page says:

use HTTP::Cookies; $cookie_jar = HTTP::Cookies->new( file => "$ENV{'HOME'}/lwp_cookies.dat", autosave => 1, ); use LWP; my $browser = LWP::UserAgent->new; $browser->cookie_jar($cookie_jar);

But you have not done that in your code. In fact nowhere have you assigned anything at all to the variable $cookie_jar as in the second line above. That is the cause of your error message. You should instantiate the jar as shown in the synopsis and then everything should be fine.

Replies are listed 'Best First'.
Re^4: Can't call method "extract_cookies" on an undefined value
by Todd Chester (Scribe) on Oct 17, 2015 at 21:29 UTC

    Editorial comment: the p, /p stuff is a pain in the neck!

    YIPPEE!!! I figured it out!

    1) Cpan errored out on me when I was trying to install perl-LWP-Protocol-https. Yum did the trick:

    # yum install perl-LWP-Protocol-https

    This gave me no end of trouble.

    Perl did not give me an error for

    use LWP::Protocol qw ( https );

    even though it was not there. LWP's "get" gave me the error.

    2) one of the "monks" (thank you!) told me how to manually include the stinkin' cookie and what the stinkin' syntax was:

    $response = $ua->get( $ClickHere, ':content_file' => './java.exe', 'Cookie' => 'oraclelicense=accept-securebackup-cookie' );

    I googled my a** off trying to figure that one out!

    3) and I figured out the proper download side for $ClickHere:

    # this on is "misdirection" (very funny guys!) # my $ClickHere = "http://download.oracle.com/otn-pub/java/jdk/7u80-b1 +5/jre-7u80-windows-i586.exe"; # This is the real one my $ClickHere = "https://edelivery.oracle.com/otn-pub/java/jdk/7u80-b1 +5/jre-7u80-windows-i586.exe";

    Thank you all for your help and support!

    -T

    #!/usr/bin/perl # Test java wget style download of Java # wget --header "Cookie: # oraclelicense=accept-securebackup-cookie" # http://download.oracle.com/otn-pub/java/jdk/7u80-b15/jre-7u80-window +s-i586.exe # Notes: # This is going in a sub. Do not use "die" # Dependancy (cpan fails here) # yum install perl-LWP-Protocol-https use strict; use warnings; use diagnostics; use Term::ANSIColor qw( BOLD RED RESET ); use LWP::UserAgent; use HTTP::Cookies qw ( extract_cookies ); use LWP::Protocol qw ( https ); use HTTP::Request qw ( request ); use constant MaxTime3 => scalar 3300; # Seconds # Indent here is so I don't have to put it back when it goes back into + a sub my $ua; my $response; my $content; my $request; my $cookie_jar; # my $ClickHere = "http://download.oracle.com/otn-pub/java/jdk/7u80-b1 +5/jre-7u80-windows-i586.exe"; my $ClickHere = "https://edelivery.oracle.com/otn-pub/java/jdk/7u80-b1 +5/jre-7u80-windows-i586.exe"; my $RevAddr = "http://www.oracle.com/technetwork/java/javase/downloads +/jre7-downloads-1880261.html"; $ua = LWP::UserAgent->new; $ua->timeout ( MaxTime3 ); $ua->show_progress ( 1 ); $response = $ua->get( $ClickHere, ':content_file' => './java.exe', 'Cookie' => 'oraclelicense=accept-securebackup-cookie' );