Thread:Project:Support desk/How to create a bot to add a new section in 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 their interested pages, and post those comments to the corresponding talk pages, which can potentially help active Wikipedians on those pages to take advantage of experts' feedback and apply them as they like to the main article.

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

As a matter of efficiency, we prefer to use python HTTP POST requests using MediaWiki API rather than available MediaWiki libraries.

We have not requested for an approval for the bot, and we are just trying to implement a trial version to test the bot on our own Talk pages.

For this purpose, I went through the following steps:

1- As discussed at https://en.wikipedia.org/wiki/Wikipedia:Creating_a_bot: >Create an account for your bot. Click here when logged in to create the account, linking it to yours. (If you do not create the bot account while logged in, it is likely to be blocked as a possible sockpuppet or unauthorised bot until you verify ownership)

>Create a user page for your bot. Your bot's edits must not be made under your own account. Your bot will need its own account with its own username and password.

So, I logged in to my own Wikipedia account, and created a new account (for the bot).

2- As discussed at https://www.mediawiki.org/wiki/API:Login: Logging in through the API requires two requests. For the first request, I wrote the following code in python:

def logInRequestToWikipedia: # Add required parameters to the request. request = { 'action' : 'login' } request['lgname'] = 'BotName' request['lgpassword'] = '*************' url = 'https://en.wikipedia.org/w/api.php' headers = { 'content-type' : 'application/x-www-form-urlencoded' } r = requests.post(url, data = json.dumps(request), headers=headers)

The response starts with an error as follows:



And continues with the API documentation.

3- As discussed at https://www.mediawiki.org/wiki/API:Edit_-_Create%26Edit_pages:

>Note: In this example, all parameters are passed in a GET request just for the sake of simplicity. However, action=edit requires POST requests; GET requests will cause an error. Do not forget to set the Content-Type header of your request to application/x-www-form-urlencoded. The token that you received is terminated with +\\, this needs to be urlencoded (so it will end with %2B%5C) before it is passed back.

I added each of the following parameters separately and both together in the request data and tried all three cases, but it returns the same response.

request['lgtoken'] = '%2B%5C' request['Content-Type'] = 'application/x-www-form-urlencoded'

4- Also I tried each of the followings in my request data, but it returns the same response:

request['format'] = 'json' request['format'] = 'xml'

Do you think the problem can be related to the fact that we have not requested for an approval for the bot yet? Because we are just trying to implement a trial version to test the bot on our own Talk pages, and apply for the approval after making sure everything will work.

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

Best regards.