instaloader: JSON Query to accounts/login/: Could not find "window._sharedData" in html response. [retrying; skip with ^C]

The code I use for this is:

import instaloader

loader = instaloader.Instaloader()

loader.login(user="", passwd="")
print("✅ 1- Logged in")

The output is:

JSON Query to accounts/login/: Could not find "window._sharedData" in html response. [retrying; skip with ^C]
JSON Query to accounts/login/: Could not find "window._sharedData" in html response. [retrying; skip with ^C]
Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/instaloader/instaloadercontext.py", line 357, in get_json
    raise QueryReturnedNotFoundException("Could not find \"window._sharedData\" in html response.")
instaloader.exceptions.QueryReturnedNotFoundException: Could not find "window._sharedData" in html response.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/instaloader/instaloadercontext.py", line 357, in get_json
    raise QueryReturnedNotFoundException("Could not find \"window._sharedData\" in html response.")
instaloader.exceptions.QueryReturnedNotFoundException: Could not find "window._sharedData" in html response.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/instaloader/instaloadercontext.py", line 357, in get_json
    raise QueryReturnedNotFoundException("Could not find \"window._sharedData\" in html response.")
instaloader.exceptions.QueryReturnedNotFoundException: Could not find "window._sharedData" in html response.

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/Users/teungrondman/Documents/projects/python/getfollowers_insta/test.py", line 5, in <module>
    loader.login(user="the_followweb", passwd="Aapje40")
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/instaloader/instaloader.py", line 634, in login
    self.context.login(user, passwd)
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/instaloader/instaloadercontext.py", line 214, in login
    csrf_json = self.get_json('accounts/login/', {}, session=session)
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/instaloader/instaloadercontext.py", line 395, in get_json
    return self.get_json(path=path, params=params, host=host, session=sess, _attempt=_attempt + 1)
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/instaloader/instaloadercontext.py", line 395, in get_json
    return self.get_json(path=path, params=params, host=host, session=sess, _attempt=_attempt + 1)
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/instaloader/instaloadercontext.py", line 383, in get_json
    raise QueryReturnedNotFoundException(error_string) from err
instaloader.exceptions.QueryReturnedNotFoundException: JSON Query to accounts/login/: Could not find "window._sharedData" in html response.

To troubleshoot this issue I tried the following:

  • Double-check your Instagram username and password for correctness
  • Disable two-factor authentication for your account temporarily and see if that resolves the issue.
  • Update the instaloader library to the latest version using pip: pip3 install --upgrade instaloader.

About this issue

  • Original URL
  • State: closed
  • Created a year ago
  • Reactions: 23
  • Comments: 35

Most upvoted comments

i am facing same issue , so i go to troubleshooting section from following link https://instaloader.github.io/troubleshooting.html search for “Login error” on page so solution is there

And you can manually transfer cookies, you need only sessionid and csrftoken. Something like this:

L = instaloader.Instaloader()
try:
    L.load_session_from_file("<your username>", "cookies.txt")
    L.get_stories()
except:
    try:
        L.login("<your username>", "<your password>")
    except:
        L.load_session("<your username>", {"sessionid": "<your session>", "csrftoken": "<your csrf>"})
        L.get_stories()
L.save_session_to_file("cookies.txt")

Of course you need to get real values instead of my placeholders. You can use any tools that your browser provide.

Facing the same error running in Docker. I have cloned the latest 4.10 from Git, and generated new session file. Receiving this error.

JSON Query to accounts/login/: Could not find "window._sharedData" in html response. [retrying; skip with ^C]
JSON Query to accounts/login/: Could not find "window._sharedData" in html response. [retrying; skip with ^C]
Loaded session from /session-filename.
Fatal error: JSON Query to accounts/login/: Could not find "window._sharedData" in html response.

Almost one month and no solution (we can’t use “get_stories()” with load_session solution), anyone have an alternative ?

In python, I followed this way and it’s solved. Thanks to @killergod143 and @aleaksah for their answers

Steps:

* Make firefox as your default browser and log in instagram with your username and password in firefox browser

* Download this [script](https://raw.githubusercontent.com/instaloader/instaloader/master/docs/codesnippets/615_import_firefox_session.py) as a .py file and run the script as:
python 615_import_firefox_session.py
* After the script is run, it will save the data inside this local path:
C:\Users\{USER}\AppData\Local\Instaloader\session-{USERNAME}

For Example: C:\Users\Acer\AppData\Local\Instaloader\session-test123
* Now copy this full file path from above and use it below:
from instaloader import Instaloader

L = Instaloader()
try:
    L.load_session_from_file("test123", r"C:\Users\Acer\AppData\Local\Instaloader\session-test123") #1st argument should be username and 2nd argument should be the saved file location
    print("Logged In Successfully")
except Exception as e:
    print("Error", e)

L.get_feed_posts()

Thanks! This fixed the problem, although I skipped the last step.

Hello Do not be tired Good time

I and several of my colleagues have been working with instaloader since the past and are still working. But for the last time (after the new update), we came across a serious problem in the login account of Instagram and we found out that not only us, but many people are facing this problem.

Code Snippet:

import instaloader

# Get instance
L = instaloader.Instaloader()

# Optionally, login or load session
L.login(USER, PASSWORD)        # (login)

error:

JSON Query to accounts/login/: Could not find "window._sharedData" in html response. [retrying; skip with ^C]
JSON Query to accounts/login/: Could not find "window._sharedData" in html response. [retrying; skip with ^C]
Traceback (most recent call last):
  File "/home/runner/code/venv/lib/python3.10/site-packages/instaloader/instaloadercontext.py", line 410, in get_json
    raise QueryReturnedNotFoundException("Could not find \"window._sharedData\" in html response.")
instaloader.exceptions.QueryReturnedNotFoundException: Could not find "window._sharedData" in html response.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/runner/code/venv/lib/python3.10/site-packages/instaloader/instaloadercontext.py", line 410, in get_json
    raise QueryReturnedNotFoundException("Could not find \"window._sharedData\" in html response.")
instaloader.exceptions.QueryReturnedNotFoundException: Could not find "window._sharedData" in html response.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/runner/code/venv/lib/python3.10/site-packages/instaloader/instaloadercontext.py", line 410, in get_json
    raise QueryReturnedNotFoundException("Could not find \"window._sharedData\" in html response.")
instaloader.exceptions.QueryReturnedNotFoundException: Could not find "window._sharedData" in html response.

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "main.py", line 5, in <module>
    L.login(..., ....)
  File "/home/runner/code/venv/lib/python3.10/site-packages/instaloader/instaloader.py", line 651, in login
    self.context.login(user, passwd)
  File "/home/runner/code/venv/lib/python3.10/site-packages/instaloader/instaloadercontext.py", line 259, in login
    csrf_json = self.get_json('accounts/login/', {}, session=session)
  File "/home/runner/code/venv/lib/python3.10/site-packages/instaloader/instaloadercontext.py", line 448, in get_json
    return self.get_json(path=path, params=params, host=host, session=sess, _attempt=_attempt + 1,
  File "/home/runner/code/venv/lib/python3.10/site-packages/instaloader/instaloadercontext.py", line 448, in get_json
    return self.get_json(path=path, params=params, host=host, session=sess, _attempt=_attempt + 1,
  File "/home/runner/code/venv/lib/python3.10/site-packages/instaloader/instaloadercontext.py", line 436, in get_json
    raise QueryReturnedNotFoundException(error_string) from err
instaloader.exceptions.QueryReturnedNotFoundException: JSON Query to accounts/login/: Could not find "window._sharedData" in html response.

To troubleshoot this issue I tried the following:

  1. Double-check your Instagram username and password for correctness
  2. I checked the code and this error with several Instagram accounts and several different usernames and passwords.
  3. Disable two-factor authentication for your account temporarily and see if that resolves the issue.
  4. Update the instaloader library to the latest version using pip: pip3 install --upgrade instaloader.

Apparently, this problem was also raised on Sep 11, 2022. (issues code 1737) But this problem has not been solved and no answer has been given.

JSON Query to accounts/login/: Could not find “window._sharedData” in html response. [retrying; skip with ^C] JSON Query to accounts/login/: Could not find “window._sharedData” in html response. [retrying; skip with ^C] Traceback (most recent call last):

I’m encountering the error. I couldn’t handle it.

As @killergod143 mentioned

follow the same steps and last step is not needed. ( Then, instaloader -l USERNAME should work fine )

It works!! Thanks 😃

I followed the instructions, and it still not working. Logged into my instragram account in Firefox. Then when I run the script, I get the following error: ImportError: attempted relative import with no known parent package

You can follow the steps from my answer 🙂

Thanks for the fast reply. I actually just downloaded wfdownloader, and was able to download 3x profiles in a few minutes. I couldn’t be bothered with the constant errors.

I had the same issue, and attempting to import my Firefox cookies as instructed on the troubleshooting page wasn’t working. I figured out that it’s because I use Firefox as my default browser, while most people are using it just to access the cookie file, so I had to change the ‘*’ in the cookie path in the code to the name of the folder for my Firefox profile (should end in ‘default-release’ instead of ‘default’).

I followed the instructions, and it still not working. Logged into my instragram account in Firefox. Then when I run the script, I get the following error: ImportError: attempted relative import with no known parent package

You can follow the steps from my answer 🙂

In python, I followed this way and it’s solved. Thanks to @killergod143 and @aleaksah for their answers

Steps:

  • Make firefox as your default browser and log in instagram with your username and password in firefox browser
  • Download this script as a .py file and run the script as:
python 615_import_firefox_session.py
  • After the script is run, it will save the data inside this local path:
C:\Users\{USER}\AppData\Local\Instaloader\session-{USERNAME}

For Example: C:\Users\Acer\AppData\Local\Instaloader\session-test123
  • Now copy this full file path from above and use it below:
from instaloader import Instaloader

L = Instaloader()
try:
    L.load_session_from_file("test123", r"C:\Users\Acer\AppData\Local\Instaloader\session-test123") #1st argument should be username and 2nd argument should be the saved file location
    print("Logged In Successfully")
except Exception as e:
    print("Error", e)

#L.get_feed_posts()

Same… still waiting for a update!

The only solution worked for me is @aleaksah’s comment above. I manually bring cookie data from chrome and it worked. Firefox method didn’t work for me.

I followed the instruction below basically and it worked!

Here are some additional info to share:

  1. I use several web browsers including Chome (main use), Waterfox G and Classic, Firefox (barely using).
  2. When I checked my login info on the browsers except for Chrome, they were all outdated and wrong. So I updated the browsers login info.
  3. I first tried to login Waterfox G, but running the script and instaloader failed as error messages “Cookie import failed: JSON Query to graphql/query: HTTP error code 401.” and “JSON Query to graphql/query: HTTP error code 401. [retrying; skip with ^C]” returned respectively. Waterfox Classic also failed.
  4. Firefox (106.0.5, which is very old) worked fine.

I do no know what “last step” in ronakjain2012’s comment mean, but both “Login to Instagram in Firefox” and “Execute the snippet, e.g. with python 615_import_firefox_session.py” seem to be needed.

i am facing same issue , so i go to troubleshooting section from following link https://instaloader.github.io/troubleshooting.html search for “Login error” on page so solution is there