T
T
Ternick2019-08-19 14:38:13
Python
Ternick, 2019-08-19 14:38:13

Why doesn't instagram auto-registration work?

THE CODE:

from user_agent import generate_user_agent
from random import choice, randint, sample
from string import ascii_letters, digits
from requests import Session, exceptions
from os.path import isfile
from re import search

def getRandomStr(length):
    return "".join(choice(ascii_letters + digits) for i in range(length))

def loginbot(proxies, email, password, username, first_name):
    try:
        session = Session()
        userAgent = generate_user_agent()
        headers = {
            'user-agent': userAgent,
            'Connection': 'keep-alive',
            'Cache-Control': 'max-age=0',
            'Upgrade-Insecure-Requests': '1',
            'Sec-Fetch-Mode': 'navigate',
            'Sec-Fetch-User': '?1',
            'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3',
            'Sec-Fetch-Site': 'none',
            'Referer': 'https://www.google.com/',
            'Accept-Language': 'ru-RU,ru;q=0.9,en-US;q=0.8,en;q=0.7,zh-CN;q=0.6,zh;q=0.5'
                }
        r = session.get("https://www.instagram.com/?hl=ru", headers=headers, proxies=proxies, verify= False)
        rollOuthash = search(r',"rollout_hash":"(\b\w*?\b)"', r.text)[0].split('"')[3]
        # cookies = r.cookies.get_dict()
        headers = {
            'user-agent': userAgent,
            'Connection': 'keep-alive',
            'Sec-Fetch-Mode': 'cors',
            'X-Instagram-AJAX': rollOuthash,
            'Content-Type': 'application/x-www-form-urlencoded',
            'Accept': '*/*',
            'X-Requested-With': 'XMLHttpRequest',
            'X-CSRFToken':  r.cookies.get_dict()['csrftoken'],
            'X-IG-App-ID': '936619743392459',
            'Origin': 'https://www.instagram.com',
            'Sec-Fetch-Site': 'same-origin',
            'Referer': 'https://www.instagram.com/accounts/emailsignup/',
            'Accept-Language': 'ru-RU,ru;q=0.9,en-US;q=0.8,en;q=0.7,zh-CN;q=0.6,zh;q=0.5',
                }
        data = {
            'email': email,
            'password': password,
            'username': username,
            'first_name': first_name,
            'seamless_login_enabled': '1',
            'tos_version': 'row',
            'opt_into_one_tap': 'false'
                }
        r = session.post("https://www.instagram.com/accounts/web_create_ajax/", headers=headers, data=data, proxies=proxies, verify= False)
        return r.json()
    except KeyError:
        return {'account_created': False, "status": "ok", 'error_type': "KeyError"}
    except exceptions.ConnectionError:
        return {'account_created': False, "status": "ok", 'error_type': "ConnectionError"}
    except exceptions.ProxyError:
        return {'account_created': False, "status": "ok", 'error_type': "ProxyError"}

def getProxy(filename):
    if isfile(filename):
        with open(filename) as f:
            proxies = f.read().strip().split('\n')
            proxies = sample(proxies, len(proxies))
        for proxy in proxies:
            try:
                yield {"https": "socks5://" + proxy, "http": "socks5://" + proxy}
            except StopIteration:
                print("Прокси закончились")
                exit()
    else:
        print("File with proxy isn't exist")
        exit()

def main():
    proxyGenerator = getProxy("proxy.txt")
    proxy = next(proxyGenerator)
    proxyUsed = 0
    mails = ['@gmail.com', '@yandex.by', '@ya.ru']
    first_names = ["Noah", "Liam", "William", "Mason", "James", "Benjamin", "Jacob", "Michael", "Elijah", "Ethan", "Emma", "Olivia", "Ava", "Sophia", "Isabella", "Mia", "Charlotte", "Abigail", "Emily", "Harper"]
    last_names = ["Abramson", "Adamson", "Adderiy", "Addington", "Adrian", "Albertson", "Aldridge", "Allford", "Alsopp", "Anderson", "Andrews", "Archibald", "Arnold", "Arthurs", "Atcheson", "Attwood", "Audley"]
    while True:
        email = getRandomStr(randint(7, 12)) + choice(mails)
        passw = getRandomStr(randint(7, 18))
        nickName = getRandomStr(randint(9, 18))
        fullname = choice(first_names) + " " + choice(last_names)
        result = loginbot(proxy, email, passw, nickName, fullname)
        if result["status"] == 'ok':
            if result['account_created']:
                print("Аккаунт был создан :", email, ":", passw)
            elif result['error_type'] == 'signup_block':
                print("Прокси были забанены")
            elif result['error_type'] == "KeyError":
                print("Кука не была обнаружена <что то новенькое>")
            elif result['error_type'] == "ConnectionError":
                print("Ошибка подключения")
            elif result['error_type'] == "ProxyError":
                print("Плохой прокси")
            else:
                print(result)
        else:
            print("Пожалуйста подождите <как это вообще возможно?>")
        proxy = next(proxyGenerator)

if __name__ == '__main__':
    main()

# https://www.instagram.com/ajax/bz:[{"page_id":"v1xv8g","app_id":"936619743392459","device_id":"XVf46wALAAF1Y1_787Xit0_a36gB","posts":,"trigger":"qex:expose","send_method":"ajax"}]

The code above :)
The beauty is that when I start comparing headers and other things when registering an account with a browser and my script, there is no difference <except that the browser makes some other requests, possibly related to the authorization process>
Is it possible that instagram could ban all proxies and there is no way around it?
Or did I still make a mistake somewhere and between my requests there is something in common that helps Instagram to ban my proxies?
Don't try it on your machine <pancake ban> {maybe 1 time} - it will unban you later, but if more than 2-3 times ban forever :(

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
steemandlinux, 2020-07-28
@steemandlinux

Requests + Instagram. People from real browsers hardly register. There are also cookies that depend on javascripts.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question