Brethren,
I'm struggling with this for a while now and it seems i can't get it to work. I have written a script to log into PM, it runs smooth, just it doesn't work/login.
use warnings; use strict; use Digest::SHA1 qw( sha1_hex ); use WWW::Mechanize; use HTTP::Cookies; use LWP::Debug qw(+); login($ARGV[0], $ARGV[1]); sub login { my ($user, $pass) = @_; my $kennung = sha1_hex("$user + $pass"); my $cookie_jar = HTTP::Cookies->new( file => "/cookies/$kennung.dat", autosave => 1, ); my $mech = WWW::Mechanize->new( cookie_jar => $cookie_jar ); my $resp = $mech->get( 'http://www.perlmonks.org?node_id=109' ); die "HTTP-Error 1\n" unless $resp->is_success; $resp = $mech->submit_form( form_name => 'login', fields => { user => $user, passwd => $pass, } ); die "HTTP-Error 2\n" unless $resp->is_success; if ( $resp->content =~ /<a href="\?node_id=109;op=logout">/ ) { print "log in ok"; } else { print "could not log in"; } }
This is the output of LWP::Debug
C:\devel>pmlogin.pl holli xxxxxxx LWP::UserAgent::new: () LWP::UserAgent::request: () HTTP::Cookies::add_cookie_header: Checking www.perlmonks.org for cooki +es HTTP::Cookies::add_cookie_header: Checking .perlmonks.org for cookies HTTP::Cookies::add_cookie_header: Checking perlmonks.org for cookies HTTP::Cookies::add_cookie_header: Checking .org for cookies LWP::UserAgent::send_request: GET http://www.perlmonks.org?node_id=109 LWP::UserAgent::_need_proxy: Not proxied LWP::Protocol::http::request: () LWP::Protocol::collect: read 847 bytes LWP::Protocol::collect: read 312 bytes LWP::Protocol::collect: read 1336 bytes LWP::Protocol::collect: read 1336 bytes LWP::Protocol::collect: read 1336 bytes LWP::Protocol::collect: read 1336 bytes LWP::Protocol::collect: read 1336 bytes LWP::Protocol::collect: read 1336 bytes LWP::Protocol::collect: read 1336 bytes LWP::Protocol::collect: read 1336 bytes LWP::Protocol::collect: read 1336 bytes LWP::Protocol::collect: read 1336 bytes LWP::Protocol::collect: read 1336 bytes LWP::Protocol::collect: read 1336 bytes LWP::Protocol::collect: read 1336 bytes LWP::Protocol::collect: read 1336 bytes LWP::Protocol::collect: read 130 bytes LWP::UserAgent::request: Simple response: OK LWP::UserAgent::request: () HTTP::Cookies::add_cookie_header: Checking www.perlmonks.org for cooki +es HTTP::Cookies::add_cookie_header: Checking .perlmonks.org for cookies HTTP::Cookies::add_cookie_header: Checking perlmonks.org for cookies HTTP::Cookies::add_cookie_header: Checking .org for cookies LWP::UserAgent::send_request: POST http://www.perlmonks.org? LWP::UserAgent::_need_proxy: Not proxied LWP::Protocol::http::request: () LWP::Protocol::collect: read 847 bytes LWP::Protocol::collect: read 1648 bytes LWP::Protocol::collect: read 1336 bytes LWP::Protocol::collect: read 1336 bytes LWP::Protocol::collect: read 1336 bytes LWP::Protocol::collect: read 1336 bytes LWP::Protocol::collect: read 1336 bytes LWP::Protocol::collect: read 1336 bytes LWP::Protocol::collect: read 1336 bytes LWP::Protocol::collect: read 1336 bytes LWP::Protocol::collect: read 1336 bytes LWP::Protocol::collect: read 1336 bytes LWP::Protocol::collect: read 1336 bytes LWP::Protocol::collect: read 1336 bytes LWP::Protocol::collect: read 1336 bytes LWP::Protocol::collect: read 310 bytes LWP::UserAgent::request: Simple response: OK could not log in
Of course I have doublechecked the credentials.


holli, /regexed monk/

In reply to problem loggin into pm by holli

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.