Skip to content

Commit

Permalink
Use GET rather than POST for API requests
Browse files Browse the repository at this point in the history
* It was just an old trick to get past some barriers which were waived with GET.
* It's not conformant and doesn't play well with some redirects.
* Some recent wikis seem to not like it at all, see also issue WikiTeam#311.
  • Loading branch information
nemobis committed Feb 8, 2020
1 parent 0eeb6bf commit 3d04dcb
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions dumpgenerator.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ def getNamespacesAPI(config={}, session=None):
namespaces = config['namespaces']
namespacenames = {0: ''} # main is 0, no prefix
if namespaces:
r = session.post(
r = session.get(
url=config['api'],
params={
'action': 'query',
Expand Down Expand Up @@ -271,7 +271,7 @@ def getPageTitlesAPI(config={}, session=None):
retryCount = 0
while retryCount < config["retries"]:
try:
r = session.post(url=config['api'], data=params, timeout=30)
r = session.get(url=config['api'], params=params, timeout=30)
break
except ConnectionError as err:
print "Connection error: %s" % (str(err),)
Expand Down Expand Up @@ -488,7 +488,7 @@ def getXMLHeader(config={}, session=None):
try:
if config['api']:
print "Trying the local name for the Special namespace instead"
r = session.post(
r = session.get(
url=config['api'],
params={
'action': 'query',
Expand Down Expand Up @@ -1158,7 +1158,7 @@ def getImageNamesAPI(config={}, session=None):
'format': 'json',
'ailimit': 500}
# FIXME Handle HTTP Errors HERE
r = session.post(url=config['api'], params=params, timeout=30)
r = session.get(url=config['api'], params=params, timeout=30)
handleStatusCode(r)
jsonimages = getJSON(r)
delay(config=config, session=session)
Expand Down Expand Up @@ -1216,7 +1216,7 @@ def getImageNamesAPI(config={}, session=None):
'iiprop': 'user|url',
'format': 'json'}
# FIXME Handle HTTP Errors HERE
r = session.post(url=config['api'], params=params, timeout=30)
r = session.get(url=config['api'], params=params, timeout=30)
handleStatusCode(r)
jsonimages = getJSON(r)
delay(config=config, session=session)
Expand Down Expand Up @@ -1736,9 +1736,9 @@ def checkAPI(api=None, session=None):
# handle redirects
for i in range(4):
print 'Checking API...', api
r = session.post(
r = session.get(
url=api,
data={
params={
'action': 'query',
'meta': 'siteinfo',
'format': 'json'},
Expand Down Expand Up @@ -2074,7 +2074,7 @@ def saveSiteInfo(config={}, session=None):
print 'Downloading site info as siteinfo.json'

# MediaWiki 1.13+
r = session.post(
r = session.get(
url=config['api'],
params={
'action': 'query',
Expand All @@ -2085,7 +2085,7 @@ def saveSiteInfo(config={}, session=None):
timeout=10)
# MediaWiki 1.11-1.12
if not 'query' in getJSON(r):
r = session.post(
r = session.get(
url=config['api'],
params={
'action': 'query',
Expand All @@ -2095,7 +2095,7 @@ def saveSiteInfo(config={}, session=None):
timeout=10)
# MediaWiki 1.8-1.10
if not 'query' in getJSON(r):
r = session.post(
r = session.get(
url=config['api'],
params={
'action': 'query',
Expand Down

0 comments on commit 3d04dcb

Please sign in to comment.