Simple python 2.7 script for logging into instagram 2021

Home   »   Simple python 2.7 script for logging into instagram 2021

import requests
import time
import random
username = 'your_username_here'
password = 'your_password_here'

def default_headers():
    return {
        'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.90 Safari/537.36',
        'Accept-Encoding': 'gzip, deflate',
        'Accept': '*/*',
        'Connection': 'keep-alive',
        'Accept-Language': 'en-US,en;q=0.8',
        'Content-Length': '0',
        'Host': '',
        'Origin': '',
        'Referer': '',
        'X-Instagram-AJAX': '1',
        'X-Requested-With': 'XMLHttpRequest'}

def sleepy():
    time.sleep(min(random.expovariate(0.6), 15.0))

#Set up our headers 
headers = default_headers()

#Set up out payload ((#Insta requires enc_password to be posted like so))
enc_password = '#PWD_INSTAGRAM_BROWSER:0:{}:{}'.format(int(time.time()), password)

#Uncomment lines below to gain a lil insight ;^
#print (enc_password)
#print (headers) 

session = requests.Session()

session.cookies.update({'sessionid': '', 'mid': '', 'ig_pr': '1',
                        'ig_vw': '1920', 'ig_cb': '1', 'csrftoken': '',
                        's_network': '', 'ds_user_id': ''})

csrf_token = session.cookies.get_dict()['csrftoken']
session.headers.update({'X-CSRFToken': csrf_token})

#sleep for a random interval: Good to use this after every request to avoid bot detect

#Post our payload
login ='', data={'enc_password': enc_password, 'username': username}, allow_redirects=True)
resp_json = login.json()

print (resp_json)

Leave a Reply

Your email address will not be published. Required fields are marked *