E
E
Egor Zavrazhnov2020-11-18 00:05:13
Python
Egor Zavrazhnov, 2020-11-18 00:05:13

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)

issues
{"user": true, "authenticated": false, "status": "ok"}'

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Artur Boyun, 2020-11-18
@arturboyun

I advise you to try selenium

P
Puma Thailand, 2020-11-18
@opium

Check headers

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question