From 9c3c992319a0a33f484cac86e818cf07df200b17 Mon Sep 17 00:00:00 2001 From: PiRSquared17 Date: Mon, 2 Mar 2015 03:13:03 +0000 Subject: [PATCH] Follow API redirects --- dumpgenerator.py | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/dumpgenerator.py b/dumpgenerator.py index 5980a6d..a4d3f11 100644 --- a/dumpgenerator.py +++ b/dumpgenerator.py @@ -1356,14 +1356,19 @@ def getParameters(params=[]): def checkAPI(api=None, session=None): """ Checking API availability """ global cj - r = session.post( - url=api, - data={ - 'action': 'query', - 'meta': 'siteinfo', - 'format': 'json'}) - resultText = r.text - print 'Checking API...', api + # handle redirects + for i in range(4): + print 'Checking API...', api + r = session.post( + url=api, + data={ + 'action': 'query', + 'meta': 'siteinfo', + 'format': 'json'}) + resultText = r.text + if r.url == api: + break + api = r.url if "MediaWiki API is not enabled for this site." in resultText: return False try: