Factorio Download API now requires CAPTCHA
Posted: Sun Jun 19, 2022 12:39 pm
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:
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")