Oh, of course, POST, thanks. Now it works, after also removing the “r” (raw string) from the token since it already has an escaped backslash, and removing urllib.parse.urlencode from the parameters. Here’s the working version in case anyone would like to see it:
#!/bin/env python
import requests
baseUrl = 'http://chlamyannotations-test2.princeton.edu/api.php'
params = {'action': 'query', 'meta': 'tokens'}
responseFilename = '/molbio2/mcahn/temp/createPagesResponse.html'
r = requests.get(baseUrl, params=params)
print(r) print(r.text)
params = {'action': 'edit', 'title': 'TestPage3', 'summary': 'Test summary', 'text': 'article content', 'token': '+\'}
f = open(responseFilename, 'w')
r = requests.post(baseUrl, data=params)
print(r) f.write(r.text) f.close()
|| Matthew Cahn | Linux Administrator | Dept. of Molecular Biology / Research Computing | Princeton University | (609) 258-5404 | mcahn@princeton.edumailto:mcahn@princeton.edu ||
On Fri, Aug 17, 2018 at 11:45 AM, Matthew H. Cahn mcahn@princeton.edu wrote:
r = requests.get(baseUrl, params=params)
print(r) print(r.text)
params = {'action': 'edit', 'title': 'TestPage3', 'summary': 'Test summary', 'text': 'article content', 'token': '+\'}
You should be using the token in the response (r) here, not hard-coding the current anonymous-user "+" token.
mediawiki-api@lists.wikimedia.org