I am writing a python function that can log into instagram using requests, I have been able to get the csrf token and add it to my header, but I am not stuck trying to make the right request to login. I have tried two headers and they both return 'Bad request'. Any help would be appreciated.
This is the header I tried to make to login
header = {
'user-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36',
'Accept-Encoding': 'gzip, deflate, br',
'cookie': f'ig_did={ig_did}; csrftoken={csrf}; mid={mid}; ig_nrcb={ig_nrcb}',
'X-Requested-With': 'XMLHttpRequest',
'Referer': 'https://www.instagram.com/accounts/login',
'x-csrftoken': csrf
}
This is the header I copied from chrome dev tools when I couldn't figure out mine
header0 = {
'authority': 'www.instagram.com',
'method': 'POST',
'path': '/accounts/login/ajax/',
'scheme': 'https',
'accept': '*/*',
'accept-encoding': 'gzip, deflate, br',
'accept-language': 'en-US,en;q=0.9',
'content-length': '273',
'content-type': 'application/x-www-form-urlencoded',
'cookie': f'ig_did={ig_did}; csrftoken={csrf}; mid={mid}; ig_nrcb={ig_nrcb}',
'origin': 'https://www.instagram.com',
'referer': 'https://www.instagram.com/',
'sec-ch-ua': 'Google Chrome;v=87, Not;A Brand;v=99, Chromium;v=87',
'sec-ch-ua-mobile': '?0',
'sec-fetch-dest': 'empty',
'sec-fetch-mode': 'cors',
'sec-fetch-site': 'same-origin',
'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36',
'x-csrftoken': csrf,
'x-ig-app-id': '936619743392459',
'x-ig-www-claim': '0',
'x-instagram-ajax': 'b10813bd9030',
'x-requested-with': 'XMLHttpRequest'
}
This is the data im sending (I am aware the password probably isnt correct)
payload = {
'username': username,
'password': f'#PWD_INSTAGRAM_BROWSER:10:{time}:{password}',
'queryParams': {},
'optIntoOneTap': 'false'
}
This is the request im sending
loginResponse = requests.post(loginUrl, data = payload, headers = header)