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

Retry login on failed save (fix for Fandom wiki farm) #188

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion mwcommands/mw_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -517,7 +517,21 @@ def save_page(self, page, text, summary, mark_as_minor, section=None):
page.save(text, summary=summary.strip(), minor=mark_as_minor, section=section)
return True
except Exception as e:
error_message('{} exception: {}'.format(type(e).__name__, e))
try:
status_message("Login failed, reattempting connection once...")
new_site = self.get_connect(True)

# Specifying host as a tuple is deprecated as of mwclient 0.10.1 and this should be
# updated to use the new scheme argument instead
# https://github.com/mwclient/mwclient/blob/99a1af21e150ab7441d1d07c86db228998ca6ffa/mwclient/client.py#L372
site_url = '{}://{}'.format(new_site.host[0], new_site.host[1])
status_message("New connection established to {}".format(site_url))

new_page = new_site.pages[page.name]
new_page.save(text, summary=summary.strip(), minor=mark_as_minor, section=section)
return True
except Exception as e:
error_message('{} exception: {}'.format(type(e).__name__, e))
return False

def page_attr(self, page, attr_name):
Expand Down