Page 1 of 1

Factorio Download API now requires CAPTCHA

Posted: Sun Jun 19, 2022 12:39 pm
by Berserker55
Hello, I was trying to follow https://wiki.factorio.com/Download_API to have an auto-downloader in my tool to make https://archipelago.gg/tutorial/Factorio/setup/en significantly simpler. However, I get "<li> Please pass the CAPTCHA. </li>" in my response, which makes this pretty much impossible. This should probably be noted on that page at the very least. I'm guessing there's not much of a solution?

in-progress download script:

Code: Select all

import requests
from Utils import is_windows, is_linux


def get_latest_factorio(user: str, password: str, version: str = "latest", build: str = "alpha"):
    if is_windows:
        distro = "win64-manual"
    elif is_linux:
        distro = "linux64"  # TODO: test
    else:
        raise NotImplemented(f"No auto downloader implemented for current platform.")

    login_url = 'https://factorio.com/login'
    with requests.Session() as client:
        client.headers.update({'Referer': login_url})
        response = client.get(login_url)
        html = response.content.decode("utf-8-sig")
        tokenstarttext = '<input id="csrf_token" name="csrf_token" type="hidden" value="'
        start = html.index(tokenstarttext)
        length = html[start:].index('">')
        token = html[start + len(tokenstarttext):start + length]
        print(token)
        login_response = client.post(login_url, data={
            "csrf_token": token,
            "username_or_email": user,
            "password": password
        })
        if "<h2>Error</h2>" in login_response.text:
            start = login_response.text.index("<h2>Error</h2>")
            print(login_response.text[start:start+250])
            return
        response = client.get(f"https://www.factorio.com/get-download/{version}/{build}/{distro}")
    return response


response = get_latest_factorio("Test", "Test")

Re: Factorio Download API now requires CAPTCHA

Posted: Mon Jun 20, 2022 5:55 am
by vinzenz
The captcha triggers on too many failed logins. Other downloaders try to replicate the games behaviour and get the token from https://wiki.factorio.com/Web_authentication_API (you'll get blocked there too if you keep trying to login with wrong info)

Be advised that these are internal APIs (-> https://wiki.factorio.com/Factorio_HTTP ... guidelines)

https://gitlab.com/moviuro/factorio-dl/ ... actorio-dl
https://github.com/narc0tiq/factorio-updater

Re: Factorio Download API now requires CAPTCHA

Posted: Mon Jun 20, 2022 8:54 am
by lyvgbfh
vinzenz wrote:
Mon Jun 20, 2022 5:55 am
The captcha triggers on too many failed logins. Other downloaders try to replicate the games behaviour and get the token from https://wiki.factorio.com/Web_authentication_API (you'll get blocked there too if you keep trying to login with wrong info)

Be advised that these are internal APIs (-> https://wiki.factorio.com/Factorio_HTTP ... guidelines)

https://gitlab.com/moviuro/factorio-dl/ ... actorio-dl
https://github.com/narc0tiq/factorio-updater
Does solving the captcha clear the block per-IP, or does it just set a cookie?

Re: Factorio Download API now requires CAPTCHA

Posted: Mon Jun 20, 2022 9:04 am
by vinzenz
lyvgbfh wrote:
Mon Jun 20, 2022 8:54 am
Does solving the captcha clear the block per-IP, or does it just set a cookie?
Solving the captcha will allow you to complete a login which gives you a session cookie. Whether we require a captcha on future logins is independent from it.