Xqt created this task.
Xqt added a project: Pywikibot.
Restricted Application added subscribers: pywikibot-bugs-list, Aklapper.
TASK DESCRIPTION
Using the redirected pywikibot.SpamfilterError leads to unexpected exception:
(Python 3.7 and Python 3.8, not sure about 3.5-3.6)
>>> import pwb, pywikibot as py
>>> from contextlib import suppress
>>> s = py.Site()
>>> p = py.Page(s, 'user:xqt/Test') # this is a protected page
>>> p.text += '\ntest edit'
Works with suppressing py.LockedPage exception only:
>>> with suppress(py.LockedPage): # works for LockedPage exception
p.save()
WARNING: API error protectedpage: This page has been protected to prevent
editing or other actions.
Works with suppressing py.SpamblacklistError and py.LockedPage exception
>>> with suppress(py.SpamblacklistError, py.LockedPage): # works too
p.save()
WARNING: API error protectedpage: This page has been protected to prevent
editing or other actions.
But fails if py.SpamfilterError is to be catched by try-except:
>>> with suppress(py.SpamfilterError, py.LockedPage): # FAILS
p.save()
WARNING: <pyshell#90>:1: DeprecationWarning: SpamfilterError is deprecated;
use SpamblacklistError instead.
WARNING: API error protectedpage: This page has been protected to prevent
editing or other actions.
Traceback (most recent call last):
File "C:\pwb\GIT\core\pywikibot\site\__init__.py", line 5404, in editpage
result = req.submit()
File "C:\pwb\GIT\core\pywikibot\data\api.py", line 2113, in submit
raise APIError(**result['error'])
pywikibot.data.api.APIError: protectedpage: This page has been protected to
prevent editing or other actions.
[help: See https://de.wikipedia.org/w/api.php for API usage. Subscribe to
the mediawiki-api-announce mailing list at
<https://lists.wikimedia.org/mailman/listinfo/mediawiki-api-announce> for
notice of API deprecations and breaking changes.]
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<pyshell#90>", line 2, in <module>
p.save()
File "C:\pwb\GIT\core\pywikibot\tools\__init__.py", line 1797, in wrapper
return obj(*__args, **__kw)
File "C:\pwb\GIT\core\pywikibot\tools\__init__.py", line 1797, in wrapper
return obj(*__args, **__kw)
File "C:\pwb\GIT\core\pywikibot\page\__init__.py", line 1301, in save
self._save(summary=summary, watch=watch, minor=minor, botflag=botflag,
File "C:\pwb\GIT\core\pywikibot\page\__init__.py", line 136, in wrapper
handle(func, self, *args, **kwargs)
File "C:\pwb\GIT\core\pywikibot\page\__init__.py", line 127, in handle
raise err
File "C:\pwb\GIT\core\pywikibot\page\__init__.py", line 115, in handle
func(self, *args, **kwargs)
File "C:\pwb\GIT\core\pywikibot\page\__init__.py", line 1313, in _save
done = self.site.editpage(self, summary=summary, minor=minor,
File "C:\pwb\GIT\core\pywikibot\site\__init__.py", line 1339, in callee
return fn(self, *args, **kwargs)
File "C:\pwb\GIT\core\pywikibot\site\__init__.py", line 5431, in editpage
raise exception(page)
pywikibot.exceptions.LockedPage: Page [[de:Benutzer:Xqt/Test]] is locked.
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<pyshell#90>", line 2, in <module>
p.save()
File "C:\Python38\lib\contextlib.py", line 369, in __exit__
return exctype is not None and issubclass(exctype, self._exceptions)
TypeError: issubclass() arg 2 must be a class or tuple of classes
>>>
The same problem exist for the other deprecated exceptions like
`UserActionRefuse` or `PageNotFound`.
But it works with Python 2.7:
>>> import pwb, pywikibot as py
WARNING: pywikibot\__init__.py:128: FutureWarning:
Python 2.7.18 will be dropped soon.
It is recommended to use Python 3.5 or above.
See T213287 for further information.
FutureWarning) # probably adjust the line no in utils.execute()
>>> s = py.Site()
>>> p = py.Page(s, 'user:xqt/Test') # this is a protected page
>>> p.text += '\ntest edit'
>>> try:
p.save()
except (py.SpamfilterError, py.LockedPage):
pass
WARNING: API error protectedpage: This page has been protected to prevent
editing or other actions.
WARNING: __main__:4: DeprecationWarning: SpamfilterError is deprecated; use
SpamblacklistError instead.
>>>
TASK DETAIL
https://phabricator.wikimedia.org/T253681
EMAIL PREFERENCES
https://phabricator.wikimedia.org/settings/panel/emailpreferences/
To: Xqt
Cc: Aklapper, Dvorapa, Xqt, pywikibot-bugs-list, JohnsonLee01, Dijkstra,
Zkhalido, Viztor, Wenyi, Tbscho, MayS, Mdupont, JJMC89, Altostratus,
Avicennasis, mys_721tx, jayvdb, Masti, Alchimista, Rxy
_______________________________________________
pywikibot-bugs mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/pywikibot-bugs