0

When I try to login to instaloader through Terminal, I get this error:

Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.9/bin/instaloader", line 33, in <module>
    sys.exit(load_entry_point('instaloader==2.2.1', 'console_scripts', 'instaloader')())
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/instaloader.py", line 1160, in main
    loader.download_profiles(args.profile, args.login.lower() if args.login is not None else None, args.password,
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/instaloader.py", line 983, in download_profiles
    self.interactive_login(username)
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/instaloader.py", line 959, in interactive_login
    self.login(username, password)
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/instaloader.py", line 516, in login
    session.headers.update({'X-CSRFToken': login.cookies['csrftoken']})
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/requests/cookies.py", line 328, in __getitem__
    return self._find_no_duplicates(name)
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/requests/cookies.py", line 399, in _find_no_duplicates
    raise KeyError('name=%r, domain=%r, path=%r' % (name, domain, path))
KeyError: "name='csrftoken', domain=None, path=None"

I have not edited or changed anything in the scripts it is showing, so I do not know what is wrong.

Richard Wilson
  • 297
  • 4
  • 17

2 Answers2

0
from instaloader import Instaloader, Profile

L = Instaloader()
username = "your username"
password = "your password"
L.login(username, password)

profile = Profile.from_username(L.context, username)
posts_sorted_by_likes = sorted(profile.get_posts(), key=lambda post: post.likes,reverse=True)
for post in posts_sorted_by_likes:
    if post.is_video:
        L.download_post(post, username)

Properly arrange the code and it will run successfully.

MangoNrFive
  • 1,541
  • 1
  • 10
  • 23
-1

If you would like to login through python script them this snippet of code will get you there

from instaloader import Instaloader
USERNAME = "YOUR USERNAME"
PASSWORD = "YOUR PASSWORD"

L = Instaloader()
L.login(USERNAME, PASSWORD)
Aditya Rajgor
  • 953
  • 8
  • 14