News:

Bored?  Looking to kill some time?  Want to chat with other SMF users?  Join us in IRC chat or Discord

Main Menu

Authorization to SMF 2.1 using Python

Started by Daretary, March 30, 2023, 04:14:14 PM

Previous topic - Next topic

Daretary

In this topic, you can see that SMF 1.1.21 authorizes fine through requests in Python.

I have to use Selenium with SMF 2.1. But in this way it takes a long time to load a long message into a topic.

What are the reasons why 2.1 refuses to work with requests? And how to fix it?

Your session timed out while posting. Please go back and try again.
I tried to fill in hidden fields, but to no avail.

Kindred

#1
Wow, that's an open ended question with no details...

If you actually want help, then providing things like, well  maybe the script which you claim used to work?

I mean, the password system and encryption changed between versions. Very little written for 1.1.x will work on 2.1.x without modification
Сл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."

Arantor

Well, that and the fact that 2.0 has session security that 1.x didn't so that external stuff needs changing...

Daretary

Kindred , sorry for not showing the code earlier.

This worked fine on SMF 1.1.21:

payload = {
    'user': 'login',
    'passwrd': 'password',
    'cookielength': '-1'
}
s = requests.Session()
p = s.post('http://site.com/index.php?action=login2', data=payload, timeout=10)

cookies = p.headers['smf_sc']
n_cookies = {}
m = re.compile('(\w+)=([a-z%0-9A-Z]+)[^;]*')
for (name, content) in re.findall(m, cookies):
    if name != "expires":
        n_cookies[name] = content

# create text content for form_data

r = s.post('http://site.com/index.php?action=post2;board=111.0', data=form_data,
           cookies=n_cookies)

I tried collecting hidden fields on action=login and then using them on action=login2. But nothing works.

Arantor

You need those hidden fields, and to supply the cookie with them as well, since the cookie contains the session ID that verifies if the other (multiple) hidden fields are correct.

Advertisement: