Beginner problem or bug?

23 views
Skip to first unread message

Oliver Heidelbach

unread,
May 26, 2015, 10:45:36 AM5/26/15
to perlw...@googlegroups.com
Hello,

I have installed the bot and tried to run a basic script compiled from
the snippets in the documentation, but the editing does not happen. The
reading seems to work fine.

I tried under Windows/Strawberry Perl and in a VM under Debian/vanilla
Perl and I always get an error message from the code where the
'$bot->edit({' is located.

It always says

Error code 0: at test.pl line xx.

I attach my script as well, feel free to play around with it as is. I am
an admin on that wiki and will change the bot credentials after a while.

I hope I only made a stupid error in the script since I really would
like to use Perl for some automated wiki updates.

#### script also attached for testing ####
#!/usr/bin/perl
use strict;
use warnings;
#use diagnostics -verbose;

# Include the MediaWiki::Bot methods in your script.
use MediaWiki::Bot qw(:constants);
#use MediaWiki::Bot;

# Username and password.
my $user = 'DS Census Bot';
my $pass = 'Afufihoda458';

#Create a Perlwikipedia object, and have it automatically log in and
configure itself
my $bot = MediaWiki::Bot->new({
assert => 'user',
protocol => 'https',
host => 'dcuniverseonline.wikia.com',
path => '',
operator => 'Datasentinel',
login_data => { username => $user, password => $pass },
debug => 1, # Turn debugging on, to see what the bot is doing
});


#Pull the wikitext of the Wikipedia Sandbox
my $article = 'Test Page - Ignore';
my $text = $bot->get_text($article);

# append something to the text
$text =~ s/Buying Price/Price Buying/g;

#control printout to screen
print $text;

#enable diagnostics;
print "before edit\n";

# Submit to Wikipedia.
# Note: This does not warn of edit conflicts, it just overwrites
existing text.
$bot->edit({
page => $article,
text => $text,
summary => 'A bot test edit',
minor => 1, # not a minor edit
});

#disable diagnostics;
print "after edit\n";

#### end of script ####

Link to the test page is
http://dcuniverseonline.wikia.com/wiki/Test_Page_-_Ignore

Regards,
Oliver Heidelbach

--
Am schwersten sind die Fragen zu beantworten, die wir uns deswegen gar
nicht erst stellen.
Michael Richter (deutscher Zeithistoriker)
test.pl

Mike Doherty

unread,
May 26, 2015, 10:59:28 AM5/26/15
to perlw...@googlegroups.com, oh...@snafu.de, oh...@snafu.de
On Tuesday, May 26, 2015 at 7:45:36 AM UTC-7, Oliver Heidelbach wrote:
# Username and password.
my $user = 'DS Census Bot';
my $pass = 'Afufihoda458';

Please make sure you change the password ;)
 
#Create a Perlwikipedia object, and have it automatically log in and
configure itself
my $bot = MediaWiki::Bot->new({
    assert      => 'user',
    protocol    => 'https',
    host        => 'dcuniverseonline.wikia.com',
    path        => '',
    operator    => 'Datasentinel',
    login_data  => { username => $user, password => $pass },
    debug       => 1, # Turn debugging on, to see what the bot is doing
});

Using the debug option will cause the library to emit information about internal operations, including the error code after editing. This is where your "Error code: 0" is coming from. I suppose that should probably include a stringification of the error code -- 0 is the "no error" error code. The library didn't detect any error for the edit -- but if the edit didn't happen, then that's a problem.

I'm not at a computer where I can test this out right now. You should inspect the return value of your edit call with Data::Dumper to find out what happened (and maybe also $bot->{error} just to be sure).

Oliver Heidelbach

unread,
Jun 15, 2015, 11:27:49 AM6/15/15
to perlw...@googlegroups.com
Hi,

has anyone had a chance to test this? Does it run on your wiki?

Before I contact the wikia.com support I would like to make sure there
is no problem with the code.

Thanks for reading and possibly testing.
Oliver Heidelbach

Natxo Asenjo

unread,
Jun 16, 2015, 4:22:42 PM6/16/15
to perlw...@googlegroups.com
hi Oliver,


On Mon, Jun 15, 2015 at 5:27 PM, Oliver Heidelbach <oh...@snafu.de> wrote:
Hi,

has anyone had a chance to test this? Does it run on your wiki?

Before I contact the wikia.com support I would like to make sure there
is no problem with the code.

Thanks for reading and possibly testing.

I just tried it and I get this:

Error code 2: 302 http://dcuniverseonline.wikia.com/api.php : error occurred when accessing https://dcuniverseonline.wikia.com/api.php after 6 attempt(s) at /tmp/test.pl line 15.
Couldn't log in with supplied settings at /tmp/test.pl line 15.
Can't call method "get_text" on an undefined value at /tmp/test.pl line 28.

maybe the credentials you initially posted are not valid any more?

--
regards,
natxo

Natxo Asenjo

unread,
Jun 16, 2015, 4:39:02 PM6/16/15
to perlw...@googlegroups.com


On Tue, Jun 16, 2015 at 10:22 PM, Natxo Asenjo <natxo....@gmail.com> wrote:
hi Oliver,

On Mon, Jun 15, 2015 at 5:27 PM, Oliver Heidelbach <oh...@snafu.de> wrote:
Hi,

has anyone had a chance to test this? Does it run on your wiki?

Before I contact the wikia.com support I would like to make sure there
is no problem with the code.

Thanks for reading and possibly testing.

I just tried it and I get this:

Error code 2: 302 http://dcuniverseonline.wikia.com/api.php : error occurred when accessing https://dcuniverseonline.wikia.com/api.php after 6 attempt(s) at /tmp/test.pl line 15.
Couldn't log in with supplied settings at /tmp/test.pl line 15.
Can't call method "get_text" on an undefined value at /tmp/test.pl line 28.

ok, I downgraded the protocol to http and now it logs in and reads the content of the page..

I think that what is going wrong is that you whant to modify the string  "Buying Prince" by "Price Buying " but that is not what is saved in the $text variable.

You can see that in $text you have the whole content of the page if you use Data::Dumper:

$VAR1 = '{{Item
 | name           = Arbiter\'s Crested Breastplate
 | icon           = [[File:Chest4 3.png||Arbiter\'s Crested Breastplate]]
 | itemID         = 1625094
 | collection     =
 | rarity         = Rare
 | item type      = Chest
 | weapon type    =
 | Morality       =
 | On Use         =
 | role           = Controller
 | style          = Talon Lord
 | censusstats    = {{CensusIDStats|1625094}}
<!-- old local stats
 | dps            =
 | defense        = 283
 | toughness      =
 | health         = 143
 | power          = 41
 | precision      = 10
 | might          = 21
 | restoration    =
 | vitalization   = 48
 | dominance      = 20
 -->
 | Socket         = Red
 | Socket bonus   = 10% Critical Power Magnitude
 | Requires Level = 30
 | itemLevel      = 60
 | renown         =
 | trade          = 0
 | integrates     =
 | Buying Price   =
 | value          = 548
 | Selling Price  = 383
 | stacks to      =
 | description    =
 | quote          =
}}
\'\'\'{{PAGENAME}}\'\'\' is a rare [[Chest Costume List|Chest item]] drop.

==Obtained from==
*[[Monarch Playing Card Company]] ([[Challenge Mode]])
*[[Eclipso]] in [[Sentinels of Magic Base (Midtown)]]

==Trivia==

==Gallery==
<gallery captionalign="center" position="center">
ChestTalonLord.jpg|Player with Arbiter\'s Crested Breastplate
</gallery>

==See also==
*[[Chest Costume List]]
*[[Chest Styles]]

{{Costumes}}';


What I usually do is replace a section. I set in the edit a comment (invisible unless you click on edit), that this section is managed by a robot and that all manual changes will be erased.

--
--
Groeten,
natxo

Oliver Heidelbach

unread,
Jun 21, 2015, 7:22:10 AM6/21/15
to perlw...@googlegroups.com
natxo,

thank you very much for your answer.
However that does not really help me.

When I do the text replacement and print the variable to my local
screen, it shows the replacement having taken place.

The error must be in the edit routine, but I am still not sure whether
it is a code problem or a problem with wikia.com.

Thus if anybody can run this code on his wiki, that information would
help me a lot.

Regards,
Oliver

Reply all
Reply to author
Forward
0 new messages