Skip to content
Snippets Groups Projects
user avatar
Adam Williamson authored
I found this while writing integration tests. If you try to login
with an incorrect username and password, mwclient correctly raises
mwclient.errors.LoginError...but if you then check logged_in, it
is True. Clearly that's wrong.

The logic for setting logged_in will basically consider us logged
in any time we process an API call and there is no 'anon' key in
the userinfo dict *or there is no userinfo dict at all*. The last
API call processed on a failed login attempt has no userinfo
dict.

This tweaks it so we only changed the logged_in value (in either
direction) if the API call we're handling has a userinfo dict.

We also fix the type of the empty userinfo we create if there
isn't one in the call (no idea why it was a tuple, it doesn't
really matter but it's weird) and explicitly set self.logged_in
to False in Site initialization. I don't think this is strictly
necessary as we can expect the init process to result in at least
one API call with a userinfo dict, but it feels more correct.

Signed-off-by: default avatarAdam Williamson <awilliam@redhat.com>
e7c51daa
History
mwclient logo

mwclient

Build status Test coverage Latest version MIT license Documentation status Issue statistics Gitter chat

mwclient is a lightweight Python client library to the MediaWiki API which provides access to most API functionality. It works with Python 3.6 and above, and supports MediaWiki 1.16 and above. For functions not available in the current MediaWiki, a MediaWikiVersionError is raised.

The current stable version 0.11.0 is available through PyPI:

$ pip install mwclient

The current development version can be installed from GitHub:

$ pip install git+git://github.com/mwclient/mwclient.git

Please see the changelog document for a list of changes.

mwclient was originally written by Bryan Tong Minh. It was maintained for many years by Dan Michael O. Heggø, with assistance from Waldir Pimenta. It is currently maintained by Marc Trölitzsch, Adam Williamson and Megan Cutrofello. The best way to get in touch with the maintainers is by filing an issue or a pull request.

Documentation

Up-to-date documentation is hosted at Read the Docs. It includes a user guide to get started using mwclient, a reference guide, implementation and development notes.

There is also some documentation on the GitHub wiki that hasn't been ported yet. If you want to help, you're welcome!

Contributing

Patches are welcome! See this page for information on how to get started with mwclient development.