Hi, I’m trying to create a page programmatically. I can get a token back from a GET, but doing an action=edit in a PUT does not create the page. The response I get back is the MediaWiki API help page.
My Python code is below. Can anyone see what I’m doing wrong?
Thanks, Matthew
#!/bin/env python
import requests import urllib import urllib.parse
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': 'TestPage', 'summary': 'Test summary', 'text': 'article content', 'token': r'+\'}
f = open(responseFilename, 'w')
r = requests.put(baseUrl, data=urllib.parse.urlencode(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 ||
mediawiki-api@lists.wikimedia.org