-
Notifications
You must be signed in to change notification settings - Fork 11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support new error format #34
Comments
PEP 654 proposes exception groups (LWN.net article), which might be an interesting answer to this question. |
Code to test the behavior with multiple errors: import mwapi
session = mwapi.Session(host='https://test.wikipedia.org',
user_agent='mwapi-errors-test (https://github.com/mediawiki-utilities/python-mwapi/issues/34; [email protected])')
token = session.get(action='query',
meta='tokens',
type='csrf')['query']['tokens']['csrftoken']
params = {
'action': 'edit',
'title': 'Sandbox',
'appendtext': 'the abuse filter will block this\nthe abuse filter will also block this',
'token': token,
}
for errorformat in ['bc', 'plaintext']:
try:
response = session.post(errorformat=errorformat, **params)
print(f'{errorformat=} did not throw, {response=}')
except mwapi.errors.APIError as exception:
print(f'{errorformat=} did throw, {exception=}') Current output:
(Notice that |
Since MediaWiki 1.29, the API can return errors in a new format (documentation): if the global
errorformat
parameter is set to anything other thanbc
(the default, for backwards compatibility), then instead of a singleerror
object, the response can contain anerrors
list of error objects. Sincemwapi
currently only checks if the response contains anerror
, if the user specifies a different error format thenmwapi
will not recognize the error(s) and instead return the result as a regular response.I’m not sure what
mwapi
should do in this case, though. Throw anAPIError
for the first error and ignore the rest? Define a new exception class for a list ofAPIError
s (which should probably derive fromAPIError
so it can still be caught like one)?The text was updated successfully, but these errors were encountered: