Use `session.get` instead of `requests.get` in `getXMLHeader`

`session.get` uses our configured User-Agent, while `requests.get` uses the default one.
pull/438/head
Pokechu22 2 years ago
parent 9808279a6a
commit 4a2cbd4843

@ -430,22 +430,22 @@ def getXMLHeader(config={}, session=None):
try:
print 'Getting the XML header from the API'
# Export and exportnowrap exist from MediaWiki 1.15, allpages from 1.18
r = requests.get(config['api'] + '?action=query&export=1&exportnowrap=1&list=allpages&aplimit=1', timeout=10)
r = session.get(config['api'] + '?action=query&export=1&exportnowrap=1&list=allpages&aplimit=1', timeout=10)
xml = r.text
# Otherwise try without exportnowrap, e.g. Wikia returns a blank page on 1.19
if not re.match(r"\s*<mediawiki", xml):
r = requests.get(config['api'] + '?action=query&export=1&list=allpages&aplimit=1&format=json', timeout=10)
r = session.get(config['api'] + '?action=query&export=1&list=allpages&aplimit=1&format=json', timeout=10)
try:
xml = r.json()['query']['export']['*']
except KeyError:
pass
if not re.match(r"\s*<mediawiki", xml):
# Do without a generator, use our usual trick of a random page title
r = requests.get(config['api'] + '?action=query&export=1&exportnowrap=1&titles=' + randomtitle, timeout=10)
r = session.get(config['api'] + '?action=query&export=1&exportnowrap=1&titles=' + randomtitle, timeout=10)
xml = r.text
# Again try without exportnowrap
if not re.match(r"\s*<mediawiki", xml):
r = requests.get(config['api'] + '?action=query&export=1&format=json&titles=' + randomtitle, timeout=10)
r = session.get(config['api'] + '?action=query&export=1&format=json&titles=' + randomtitle, timeout=10)
try:
xml = r.json()['query']['export']['*']
except KeyError:

Loading…
Cancel
Save