Python login error using python

I am trying to login to my instagram via python script using argparse. It seems to be connecting, but it prints: β€œThis page cannot be loaded. If cookies are disabled in your browser or you are viewing in private mode, try turning on cookies or turning off private mode, and then repeat the action.” Here is my code:

import argparse import mechanicalsoup from bs4 import BeautifulSoup parser = argparse.ArgumentParser(description='Login to Instagram.') parser.add_argument("username") parser.add_argument("password") args = parser.parse_args() browser = mechanicalsoup.Browser() login_page = browser.get("https://instagram.com/accounts/login/?force_classic_login=&next=/oauth/authorize/?client_id=9d836570317f4c18bca0db6d2ac38e29%26redirect_uri=http://websta.me/%26response_type=code%26scope=comments%2Brelationships%2Blikes") # we grab the login form login_form = login_page.soup.select(".dialog-main")[0].select("#login-form")[0] # specify username and password login_form.select("#id_username")[0]['value'] = args.username login_form.select("#id_password")[0]['value'] = args.password #submit page2 = browser.submit(login_form, login_page.url) #verify login p = page2.soup.p.string print(p) print(args.password) 
+3
source share
2 answers

There is a library for instagram access from python . To log in, you need the following code:

 from instagram.client import InstagramAPI access_token = "YOUR_ACCESS_TOKEN" # get this from instagram client_secret = "YOUR_CLIENT_SECRET" # this, too, from instagram api = InstagramAPI(access_token=access_token, client_secret=client_secret) recent_media, next_ = api.user_recent_media(user_id="userid", count=10) for media in recent_media: print media.caption.text 

In other words, do not reinvent the wheel.

+1
source

In this answer, you also need to include the client secret key for entering the API using this library.

Python API client debugging - "NoneType" does not have len ()

0
source

All Articles