Thread:Project:Support desk/How to create a bot to add a new section to a talk page?

Hi there,

We are a group of researchers, trying to find a practical way to motivate professors and researchers who have published a fair number of research papers, to review Wikipedia pages and improve them.

As they do not usually have enough time to edit Wikipedia pages, we are trying to ask their comments on related pages, and post those comments to the corresponding talk pages, which can potentially help active Wikipedians on those pages to take advantage of experts' feedbacks and apply them as they like to the main article.

To this end, we need to implement a bot which posts new sections on Talk pages.

As a matter of efficiency, we prefer to use python hTTP POST requests from our server to Wikipedia server, and we are using MediaWiki API.

We have not requested for an approval for the bot, and we are just trying to implement a trial version.

The problem is with authentication of the bot.

As discussed at https://www.mediawiki.org/wiki/API:Login, logging in through the API requires two requests, but sending the first request returns an error as follows:



And there is no token to use in the second request.

Our login function in python is as follows:

def logInRequestToWikipedia:

# Add required parameters to the request. request = { 'action' : 'login' } request['format'] = 'json' request['lgname'] = 'PostOnTalk' request['lgpassword'] = '*************' request['lgtoken'] = '%2B%5C'

url = 'https://en.wikipedia.org/w/api.php'

headers = { 'User-Agent' : 'MyCoolTool/1.1 (http://example.com/MyCoolTool/; MyCoolTool@example.com) BasedOnSuperLib/1.4' } headers['content-type'] = 'application/x-www-form-urlencoded'

r = requests.post(url, data = json.dumps(request), headers=headers)

We will appreciate it if you help us with this issue.

Best regards.