Answer the question
In order to leave comments, you need to log in
How to login to instagram using requests?
what did I do wrong?
import requests
url = ' https://www.instagram.com/'
res_get = requests.get(url)
print(dict(res_get.cookies))
# print(dict(res_get.headers))
cookies = ""
for i in dict(res_get.cookies):
cookies += i + "=" + dict(res_get.cookies)[i] + ";"
headers = {
'accept': "*/*",
'accept-encoding': "gzip, deflate, br",
'accept-language': "ru-RU,ru;q=0.8,en-US;q=0.5,en;q=0.3",
"Connection": "keep-alive",
'content-type': "application/x-www-form-urlencoded",
"Cookie": cookies,
'host': "www.instagram.com",
'origin': "https://www.instagram.com",
'referer': "https://www.instagram.com/accounts/login/",
'user-agent': "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:82.0) Gecko/20100101 Firefox/82.0",
'x-csrftoken': dict(res_get.cookies)['csrftoken'],
"X-IG-App-ID": "936619743392459",
"X-IG-WWW-Claim": "hmac.AR3xiqmyRCRKtVFphRfBT8Ag3OkPikIJzny-92gbtwYdODgY",
'x-instagram-ajax': "ff978a563a27",
'x-requested-with': "XMLHttpRequest",
}
data = {
"username": "user",
"enc_password": "pass",
"queryParams": "{}",
"optIntoOneTap": "false"
}
url_p = 'https://www.instagram.com/accounts/login/ajax/'
r = requests.post(url=url_p, headers=headers, data=data)
print(r.content)
{"user": true, "authenticated": false, "status": "ok"}'
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question