News:

Wondering if this will always be free?  See why free is better.

Main Menu

Login and reply to thread with python

Started by officialNecro, March 21, 2018, 06:34:11 AM

Previous topic - Next topic

officialNecro

Hello,
I'm looking to integrate a SMF forum into discord through the use of a bot. In order to do so, I created a script that logs in a general user, which members from discord can use to post on the site. I've been testing the script but I just can't seem to maintain the login session. I manage to login and it redirects me to the index page but when I try to post using the same session it tells me my session has expired and I need to login again. I'm wondering if anyone has managed to do so or knows of why the session is expiring prematurely.

P.S. Not actual password and username

import requests

url = "https://modding-union.com/index.php?action=login2"

username = "validusername"
password = "validpassword"

headers = {
    "User-Agent": "botto",
    "Content-Type" : "text/html"
}
payload = {
    "passwrd": password,
    "user":username,
    "cookielength": "800",
}

session = requests.Session()

r = session.post(url, headers=headers, data=payload)

reply_url = "https://modding-union.com/index.php?action=post2;start=120;board=390"

thread_url = "https://modding-union.com/index.php/topic,34267.105.html"

post_data = {
    "subject" : "Re:Narya",
    "message" : "I support this, +1"
}

r = requests.post(reply_url, headers=headers, data=post_data, cookies=cookies)
#this statement fails and returns a page saying session expired

Kindred

Слaва
Украинi

Please do not PM, IM or Email me with support questions.  You will get better and faster responses in the support boards.  Thank you.

"Loki is not evil, although he is certainly not a force for good. Loki is... complicated."

Advertisement: