Page 1 of 1

Can't pass csrf token on factorio.com/login

Posted: Fri Apr 12, 2019 8:11 pm
by Zickfor
I need help with non-browser factorio.com auth.

I read instructions a lot of times maybe i am bit idiot, but anyway:

Code: Select all

import requests
from bs4 import BeautifulSoup

s = requests.session()
data = s.get('https://www.factorio.com/login')

soup = BeautifulSoup(data.content, 'html.parser')
token = soup.find_all('input', id='csrf_token')[0]['value']

newdata = s.post('https://www.factorio.com/login?csrf_token='+str(token)+'&username_or_email=&password=')
Returned page is saying, that 'The CSRF token is missing.'

Re: Can't pass csrf token on factorio.com/login

Posted: Mon Mar 09, 2020 4:24 pm
by Orygeunik
If yet actual, that fix this problem can with add header Referer.

For example this http request returned error (Token, session and password replaced to star (*)):

Code: Select all

POST /login HTTP/1.1
Host: www.factorio.com
Connection: keep-alive
Content-Length: 179
Content-Type: application/x-www-form-urlencoded
Cookie: session=***

csrf_token=***&next=&username_or_email=orygeunik&password=***&action=Login
This http request returned redirect (it's a normal action) (Token, session and password replaced to star (*)):

Code: Select all

POST /login HTTP/1.1
Host: www.factorio.com
Connection: keep-alive
Content-Length: 179
Content-Type: application/x-www-form-urlencoded
Referer: https://www.factorio.com/login
Cookie: session=***

csrf_token=***&next=&username_or_email=orygeunik&password=***&action=Login