Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

MediaWiki::API badtoken every now and then

by Skeeve (Parson)
on Mar 28, 2018 at 14:21 UTC ( [id://1211919]=perlquestion: print w/replies, xml ) Need Help??

Skeeve has asked for the wisdom of the Perl Monks concerning the following question:

What could be the reason for intermittend "badtoken" errors when using MediaWiki::API's edit function?

In my script, sometimes I get that error. When I restart the script, it usually works.

I now inserted code to reconnect to my wiki in case a badtoken happens, but I'm wondering how I could debug the issus as it seems to be non-reproducible.

Update: The reconnect code helped. In my last run of updating 378 entries I received a bad token once. After reconnecting it worked.

my $retries= 3; while ($retries--) { last if $mw->edit( { action => 'edit', title => $pagename, basetimestamp => $timestamp, # to avoid edit conflicts text => $text } ); if ( 3 != $mw->{error}->{code} ) { warn "Don't know how to handle " . $mw->{error}->{details}. ' +('. $mw->{error}->{code} . ')'; exit 1; } if (1 > $retries) { warn "No more retries. Giving up on " . $mw->{error}->{details +}. ' ('. $mw->{error}->{code} . ')'; exit 2; } warn "Reconnecting...\n" if $verbose; $mw->logout(); $mw->login( { lgname => $settings->{USER}, lgpassword => $settings +->{PASS} } ) || die $mw->{error}->{details}. ' ('. $mw->{error}->{code} . ') +'; }

s$$([},&%#}/&/]+}%&{})*;#$&&s&&$^X.($'^"%]=\&(|?*{%
+.+=%;.#_}\&"^"-+%*).}%:##%}={~=~:.")&e&&s""`$''`"e

Replies are listed 'Best First'.
Re: MediaWiki::API badtoken every now and then
by hippo (Bishop) on Mar 28, 2018 at 14:44 UTC
Re: MediaWiki::API badtoken every now and then
by marto (Cardinal) on Mar 28, 2018 at 14:51 UTC

      Maybe it's related but mine was an "badtoken: Invalid token".


      s$$([},&%#}/&/]+}%&{})*;#$&&s&&$^X.($'^"%]=\&(|?*{%
      +.+=%;.#_}\&"^"-+%*).}%:##%}={~=~:.")&e&&s""`$''`"e

        A quick glance doesn't find this in MediaWiki::API, perhaps the server is returning this. If I were you I'd review all open tickets (note people reporting that it doesn't login properly anymore), some testing should narrow down where the problem(s?) are.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://1211919]
Approved by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others studying the Monastery: (6)
As of 2024-04-18 22:17 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found