Skip to content
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

Bug encountered during accessing local Wiki #79

Closed
jkpubsrc opened this issue Mar 20, 2020 · 7 comments
Closed

Bug encountered during accessing local Wiki #79

jkpubsrc opened this issue Mar 20, 2020 · 7 comments

Comments

@jkpubsrc
Copy link

jkpubsrc commented Mar 20, 2020

Python 3.5.2 (default, Oct  8 2019, 13:06:37) 
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from mediawiki import MediaWiki
>>> mw = MediaWiki(url="http://192.168.10.3:10080/mywiki/api.php")
Traceback (most recent call last):
  File "/XXXXXXX/barrust-mediawiki/mediawiki/mediawiki/mediawiki.py", line 92, in __init__
    self._get_site_info()
  File "/XXXXXXX/barrust-mediawiki/mediawiki/mediawiki/mediawiki.py", line 868, in _get_site_info
    raise MediaWikiException("Missing query in response")
mediawiki.exceptions.MediaWikiException: An unknown error occured: "Missing query in response". Please report it on GitHub!

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/XXXXXXX/barrust-mediawiki/mediawiki/mediawiki/mediawiki.py", line 94, in __init__
    raise MediaWikiAPIURLError(url)
mediawiki.exceptions.MediaWikiAPIURLError: http://192.168.10.3:10080/mywiki/api.php is not a valid MediaWiki API URL

Wiki is valid, works perfectly, API is enabled. The Wiki version is quite recent: 1.33.0
Hm, so what do do now?

@barrust
Copy link
Owner

barrust commented Mar 20, 2020

Strange, I don't have a local instantiation of a media wiki anymore, but have you confirmed that the api url that you used loads the api page?

If not, it could be that there was a change to the API since the last time I looked at this project that would cause that issue.

@jtmullen
Copy link

jtmullen commented Apr 20, 2020

I am also seeing this error on a production wiki on 1.31 LTS. I've tracked it down the response the wiki is giving and it seems that the wiki it is a permissions error.

The init and set_api_url functions will request api info from the wiki. However, for wikis that require login for all actions this won't work since you aren't logged in. Unfortunately it doesn't look like this library provides a way to do the login before it attempts to make this request. I was able to hack a quick way to do it and got it working for me locally, but I think fixing it in this library will take a bit more work.

Here is the response from my wiki for reference:
{u'error': {u'info': u'You need read permission to use this module.', u'*': u'See {{api url}} for API usage. Subscribe to the mediawiki-api-announce mailing list at &lt;https://lists.wikimedia.org/mailman/listinfo/mediawiki-api-announce&gt; for notice of API deprecations and breaking changes.', u'code': u'readapidenied'}}

@barrust
Copy link
Owner

barrust commented Apr 20, 2020

This is interesting; would you be willing to show me what type of hack you pulled together to make it so you login before accessing the wiki? Most likely, we would want to add username/password as potential parameters to the wiki object initialization and use the presence of those to log into the wiki. Thoughts?

@jtmullen
Copy link

I just made the quickest change I could see that would potentially allow me to try out using the library.

I moved the _get_site_info() call out of set_api_url and put it at the end of login.
Then I just made sure to call login in right after setting the url so hopefully there wouldn't be any side effects I didn't foresee. Its still possible there could be problems with doing so if the url is actually bad as the current login function might assume that the url has already been validated. That is something the existing checking is supposed to catch, but it can't do so until after login as is.

As far as fixes, yeah I think adding login info as an option to the initialization, and making sure to login before making any other calls would work. The login and set_api_url would still not work. Perhaps an overloaded set_api_url that accepts a username and password to then login and set the url in the right order.

@barrust
Copy link
Owner

barrust commented Apr 21, 2020

@jtmullen would you be willing to try using the following branch? I believe I made it possible to login during initialization but I do not have a mediawiki site to test against.

@jkpubsrc does this seem to be analogous to the issue you ran into? Was your local wiki requiring login to access the API?

@jtmullen
Copy link

@barrust was just able to give it a try, seems to work perfectly! I did try both passing in the url, username, and password at initialization and via set_api_url after initialization and both were able to successfully login and access the wiki without issue

@barrust
Copy link
Owner

barrust commented Apr 22, 2020

Wonderful! I released a new version and uploaded to pypi! @jkpubsrc if this didn't resolve your issue, please reopen this ticket.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants