Page MenuHomePhabricator

Pywikibot cannot save javascript protected page
Closed, InvalidPublic

Description

I'm with my framabot user-config. I can save change on website, but I can't edit Utilisateur:Framabot/categories.js (move later) with pywikibot, and other pages works :

>>> import pywikibot
>>> d = pywikibot.Page(pywikibot.Site('fr', 'wikipedia'), "Utilisateur:Framabot/categories.js")
>>> d.text = ''
>>> d.save()
Sleeping for 7.3 seconds, 2016-11-20 19:53:58
WARNING: API error unknownerror: Unknown error: "mycustomjsprotected"
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "pywikibot\tools\__init__.py", line 1447, in wrapper
    return obj(*__args, **__kw)
  File "pywikibot\page.py", line 1209, in save
    cc=apply_cosmetic_changes, quiet=quiet, **kwargs)
  File "pywikibot\page.py", line 1235, in _save
    raise pywikibot.OtherPageSaveError(self, err)
pywikibot.exceptions.OtherPageSaveError: Edit to page [[Utilisateur:Framabot/categories.js]] failed:
unknownerror: Unknown error: "mycustomjsprotected" [help:See https://fr.wikipedia.org/w/api.php for API usage]

Event Timeline

Looks like you hit https://doc.wikimedia.org/mediawiki-core/master/php/classTitle.html#a9fdfdd6a672afcdfcbcc7e83e688a95f . I assume you're editing with user:Framabot? According to https://fr.wikipedia.org/wiki/Sp%C3%A9cial:Liste_des_droits_de_groupe every user is able to edit their own css/js. I would first try to do a manual edit on the api to see if you can reproduce it to rule out an upstream problem.

Could You double-confirm that You have been logged in as Framabot.

I was able to recreate issue, when I was logged in on bot account and tried to change my personal JS file.

Same shell for all these commands :

>>> import pywikibot
>>> d = pywikibot.Page(pywikibot.Site('fr', 'wikipedia'), "Utilisateur:Framabot/categories.js")
>>> d.text
u''
>>> d.exists()
False
>>> d.text = 'hello'
>>> d.save()
WARNING: API error unknownerror: Unknown error: "mycustomjsprotected"
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "pywikibot\tools\__init__.py", line 1447, in wrapper
    return obj(*__args, **__kw)
  File "pywikibot\page.py", line 1209, in save
    cc=apply_cosmetic_changes, quiet=quiet, **kwargs)
  File "pywikibot\page.py", line 1235, in _save
    raise pywikibot.OtherPageSaveError(self, err)
pywikibot.exceptions.OtherPageSaveError: Edit to page [[Utilisateur:Framabot/categories.js]] failed:
unknownerror: Unknown error: "mycustomjsprotected" [help:See https://fr.wikipedia.org/w/api.php for API usage]
>>> d = pywikibot.Page(pywikibot.Site('fr', 'wikipedia'), "Utilisateur:Framawiki/Brouillon")
>>> d.exists()
True
>>> d.text = 'hello'
>>> d.save()
Page [[Utilisateur:Framawiki/Brouillon]] saved

And save this edit.
I will try with my main account and with an existing js page.

And it's ok if I edit an existing JS page with main account Framawiki...

>>> import pywikibot
>>> d = pywikibot.Page(pywikibot.Site('fr', 'wikipedia'), "Utilisateur:Framawiki/js/editTitre.js")
>>> d.text = 'hello'
>>> d.save('test')
Password for user Framawiki on wikipedia:fr (no characters will be shown):
Logging in to wikipedia:fr as Framawiki
WARNING: API warning (login): Main-account login via action=login is deprecated and may stop working without warning. To continue login with action=login, see [[Special:BotPasswords]]. To safely continue using main-account login, see action=clientlogin.
Page [[wikipedia:fr:Utilisateur:Framawiki/js/editTitre.js]] saved

do this

Another test with Framabot's user-config, to save text on an existing page.

>>> import pywikibot
>>> d = pywikibot.Page(pywikibot.Site('fr', 'wikipedia'), "Utilisateur:Framabot/test.js")
>>> d.exists()
True
>>> d.text
u'hello !'
>>> d.text = u'test'
>>> d.save(u'test !')
WARNING: API error unknownerror: Unknown error: "mycustomjsprotected"
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "pywikibot\tools\__init__.py", line 1447, in wrapper
    return obj(*__args, **__kw)
  File "pywikibot\page.py", line 1209, in save
    cc=apply_cosmetic_changes, quiet=quiet, **kwargs)
  File "pywikibot\page.py", line 1235, in _save
    raise pywikibot.OtherPageSaveError(self, err)
pywikibot.exceptions.OtherPageSaveError: Edit to page [[Utilisateur:Framabot/test.js]] failed:
unknownerror: Unknown error: "mycustomjsprotected" [help:See https://fr.wikipedia.org/w/api.php for API usage]

It's looks like bug only concern bot accounts, can you check with yours ? I'll try with API Sandbox.

>>> import pywikibot
>>> d = pywikibot.Page(pywikibot.Site('fr', 'wikipedia'), "Utilisateur:MagulBot/categories.js")
>>> d.exists()
False
>>> d.text = 'T151163'
>>> d.save()
Page [[Utilisateur:MagulBot/categories.js]] saved
...
>>> pywikibot.Site('fr', 'wikipedia').logged_in()
>>> pywikibot.Site('fr', 'wikipedia').user()

It looks that it works for my bot account (see: 1). Another question is how You bot is logged in into fr.wiki?

OAuth creds in user-config. I'll try with normal password...

Edit : with a "normal" userconfig (just username "Framabot" in it, no creds)

>>> import pywikibot
>>> pywikibot.Site('fr', 'wikipedia').user()
>>> d = pywikibot.Page(pywikibot.Site('fr', 'wikipedia'), "Utilisateur:Framabot/test.js")
>>> d
Page(Utilisateur:Framabot/test.js)
>>> d.text
u'test !'
>>> d.text = u'T151163'
>>> d.save('T151163')
Password for user Framabot on wikipedia:fr (no characters will be shown):
Logging in to wikipedia:fr as Framabot
WARNING: API warning (login): Main-account login via action=login is deprecated and may stop working without warning. To continue login with action=login, see [[Special:BotPasswords]]. To safely continue using main-account login, see action=clientlogin.
Page [[wikipedia:fr:Utilisateur:Framabot/test.js]] saved

It's works ! (sorry for spam)

It's not spam at all. If You will find any other bug don't hesitate to report. It looks that Your OAuth consumer doesn't have rights to edit custem JS/CSS (see: 1). I'm closing it.

.. Thank you !
Do you think that it can be fine from mediawiki to show a better error message ?

.. Thank you !
Do you think that it can be fine from mediawiki to show a better error message ?

Or Pywikibot could do more. Pywikibot could check before editing if it has a certain right or list the rights it has when it runs into a rights problem.

Could You, please raport new issue (with clean comment history) for improve logging when bot is logged as OAuth (and maybe bot password)?