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

API login retry logic not working #69

Closed
audiodude opened this issue Aug 21, 2019 · 4 comments · Fixed by #78 or #80
Closed

API login retry logic not working #69

audiodude opened this issue Aug 21, 2019 · 4 comments · Fixed by #78 or #80
Assignees
Labels
bug p0 High Priority bug

Comments

@audiodude
Copy link
Member

audiodude commented Aug 21, 2019

The retry logic that was added in d5769dd is not working.

Here is the relevant snippet from the logs:

INFO:wp1.tables:Uploading wikicode to Wikipedia: Adele
WARNING:wp1.api:Got login exception, retrying login
DEBUG:urllib3.connectionpool:Starting new HTTPS connection (1): en.wikipedia.org:443
DEBUG:urllib3.connectionpool:https://en.wikipedia.org:443 "GET /w/api.php?meta=siteinfo%7Cuserinfo%7Cuserinfo&siprop=general%7Cnamespaces&uiprop=groups%7Crights%7Cblockinfo%7Chasmsg&continue=&action=query&format=json HTTP/1.1" 200 2220
DEBUG:urllib3.connectionpool:https://en.wikipedia.org:443 "GET /w/api.php?meta=tokens&type=login&action=query&format=json HTTP/1.1" 200 110
DEBUG:urllib3.connectionpool:https://en.wikipedia.org:443 "POST /w/api.php HTTP/1.1" 200 88
DEBUG:urllib3.connectionpool:https://en.wikipedia.org:443 "GET /w/api.php?meta=userinfo%7Cuserinfo&uiprop=groups%7Crights%7Cblockinfo%7Chasmsg&continue=&action=query&format=json HTTP/1.1" 200 280
00:00:24 mwclient.errors.AssertUserFailedError: By default, mwclient protects you from accidentally editing without being logged in. If you actually want to edit without logging in, you can set force_login on the Site object to False.
Traceback (most recent call last):
  File "/usr/src/app/wp1/api.py", line 48, in save_page
    page.save(wikicode, msg)
  File "/usr/local/lib/python3.7/site-packages/mwclient/page.py", line 182, in save
    raise mwclient.errors.AssertUserFailedError()
mwclient.errors.AssertUserFailedError: By default, mwclient protects you from accidentally editing without being logged in. If you actually want to edit without logging in, you can set force_login on the Site object to False.

My current best guess, from looking at the mwclient code, is that the page object keeps a reference to the site it was pulled from, so that logging in again on the global site object perhaps doesn't do anything.

The other problem is that this is hard to test on Wikipedia, since the login time is presumably pretty long.

@audiodude audiodude added the bug label Aug 21, 2019
@audiodude
Copy link
Member Author

This is, of course, why the bot didn't upload any tables today.

@audiodude audiodude added the p0 High Priority bug label Aug 21, 2019
@audiodude
Copy link
Member Author

I've restarted the upload worker and requeued the failed jobs. Some of them that failed were also update jobs, which seem to have some kind of stale database connection as well.

@audiodude
Copy link
Member Author

The attempted fix (no-op token refresh) didn't work. Next step is to fork the mwclient repo and attempt a fix there.

@audiodude audiodude reopened this Aug 24, 2019
@audiodude
Copy link
Member Author

I tried replicating some of the code that I use in api.py in a simple script so I could inspect the results. Interestingly, I got the following when trying the second login attempt:

mwclient.errors.LoginError: Cannot log in when using MediaWiki\Session\BotPasswordSessionProvider sessions

I think the answer might just be to throw out the entire mwclient Site object when a retry is necessary.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug p0 High Priority bug
Projects
None yet
1 participant