Troubleshooting

429 Too Many Requests

Instaloader has a logic to keep track of its requests to Instagram and to obey their rate limits. The rate controller assumes that

  • at one time, Instaloader is the only application that consumes requests, i.e. neither the Instagram browser interface, nor a mobile app, nor another Instaloader instance is running in parallel, and

  • no requests had been consumed when Instaloader starts.

The latter one implies that restarting or reinstantiating Instaloader often within short time is prone to cause a 429.

Since the behavior of the rate controller might change between different versions of Instaloader, make sure to use the current version of Instaloader, especially when encountering many 429 errors.

If a request is denied with a 429, Instaloader retries the request as soon as the temporary ban is assumed to be expired. In case the retry continuously fails for some reason, which should not happen under normal conditions, consider adjusting the --max-connection-attempts option.

There have been observations that services, that in their nature offer promiscuous IP addresses, such as cloud, VPN and public proxy services, might be subject to significantly stricter limits for anonymous access. However, logged-in accesses (see --login) do not seem to be affected.

Instaloader allows to adjust the rate controlling behavior by overriding instaloader.RateController.

Too many queries in the last time

“Too many queries in the last time” is not an error. It is a notice that the rate limit has almost been reached, according to Instaloader’s own rate accounting mechanism.

Instaloader allows to adjust the rate controlling behavior by overriding instaloader.RateController.

Private but not followed

You have to follow a private account to access most of its associated information.

Login error

Instaloader’s login should work fine, both with and without Two-Factor-Authentication. It also supports handling the checkpoint challenge, issued when Instagram suspects authentication activity on your account, by pointing the user to an URL to be opened in a browser.

Nevertheless, in Issue #92, Issue #615, Issue #1150 and Issue #1217, users reported problems with logging in. We recommend to always keep the session file which Instaloader creates when using --login. If a session file is present, --login does not make use of the failure-prone login procedure. Also, session files usually do not expire.

If you do not have a session file present, you may use the following script (Example 615_import_firefox_session.py) to workaround login problems by importing the session cookies from Firefox and bypassing Instaloader’s login and so still use Instaloader’s logged-in functionality.

from argparse import ArgumentParser
from glob import glob
from os.path import expanduser
from platform import system
from sqlite3 import OperationalError, connect

try:
    from instaloader import ConnectionException, Instaloader
except ModuleNotFoundError:
    raise SystemExit("Instaloader not found.\n  pip install [--user] instaloader")


def get_cookiefile():
    default_cookiefile = {
        "Windows": "~/AppData/Roaming/Mozilla/Firefox/Profiles/*/cookies.sqlite",
        "Darwin": "~/Library/Application Support/Firefox/Profiles/*/cookies.sqlite",
    }.get(system(), "~/.mozilla/firefox/*/cookies.sqlite")
    cookiefiles = glob(expanduser(default_cookiefile))
    if not cookiefiles:
        raise SystemExit("No Firefox cookies.sqlite file found. Use -c COOKIEFILE.")
    return cookiefiles[0]


def import_session(cookiefile, sessionfile):
    print("Using cookies from {}.".format(cookiefile))
    conn = connect(f"file:{cookiefile}?immutable=1", uri=True)
    try:
        cookie_data = conn.execute(
            "SELECT name, value FROM moz_cookies WHERE baseDomain='instagram.com'"
        )
    except OperationalError:
        cookie_data = conn.execute(
            "SELECT name, value FROM moz_cookies WHERE host LIKE '%instagram.com'"
        )
    instaloader = Instaloader(max_connection_attempts=1)
    instaloader.context._session.cookies.update(cookie_data)
    username = instaloader.test_login()
    if not username:
        raise SystemExit("Not logged in. Are you logged in successfully in Firefox?")
    print("Imported session cookie for {}.".format(username))
    instaloader.context.username = username
    instaloader.save_session_to_file(sessionfile)


if __name__ == "__main__":
    p = ArgumentParser()
    p.add_argument("-c", "--cookiefile")
    p.add_argument("-f", "--sessionfile")
    args = p.parse_args()
    try:
        import_session(args.cookiefile or get_cookiefile(), args.sessionfile)
    except (ConnectionException, OperationalError) as e:
        raise SystemExit("Cookie import failed: {}".format(e))

To use this script,

  1. Download the script: Example 615_import_firefox_session.py,

  2. Login to Instagram in Firefox,

  3. Execute the snippet, e.g. with python 615_import_firefox_session.py,

  4. Then, instaloader -l USERNAME should work fine.

This script also supports specifying a cookie file path, which may be useful if you use multiple Firefox profiles or if your operating system has the directory structure differently set up. Also, you can specify an alternative session file path.

Next Section

Contributing to Instaloader