Forum:Please tell me why this bot isn't working

From Orain Meta
Jump to navigation Jump to search
Forums: Index Support

Lieutenant S., Geschichtsmeister des Lexipedium (talk) 15:03, 18 August 2014 (BST)
Editing part of the script
# Getting an edit token
post_request = {"action":"query","prop":"info|revisions","intoken":"edit","titles":"Encyclopedia Muricana:Sandbox","format":"json"}
req = requests.post("http://encyclopediamuricana.us/w/api.php", data=post_request, cookies=cookies)
r_json = json.dumps(req.json())
r_json = json.loads(r_json)
cookies = req.cookies

print req.json()

edittoken = r_json[u"query"][u"pages"][u"-1"][u"edittoken"]
#edittoken = edittoken.replace("+\\","")
edittoken = str(edittoken)
edittoken = urllib.quote_plus(edittoken)
print edittoken

# Making an edit
edittext = "Bot edit"
edittext = urllib.quote_plus(edittext)
post_request = {"format":"json","action":"edit","title":"Encyclopedia Muricana:Sandbox","appendtext":edittext,"token":edittoken}
headers = {"Content-Type":"application/x-www-form-urlencoded"}
req = requests.post("http://encyclopediamuricana.us/w/api.php", headers=headers, data=post_request, cookies=cookies)
print req.json()
Error
{u'servedby': u'prod4', u'error': {u'info': u'Invalid token', u'code': u'badtoken'}}

Lieutenant S., Geschichtsmeister des Lexipedium (talk) 15:03, 18 August 2014 (BST)