pythoninstagraminstaloader

Instaloader: JSON Query to explore/tags/hashtag/: 404 Not Found


I am constantly getting an error where when I try to scrape posts from a specific hashtag using instaloader, I am getting the error: JSON Query to explore/tags/hashtag/: 404 Not Found Here is my script:

from itertools import islice
import instaloader

username = ''
password = ''
hashtag = 'food'

L = instaloader.Instaloader()
L.login(username, password)

posts = L.get_hashtag_posts(hashtag)

for post in posts:
    print(post.url)

and here is the full error messsage:

JSON Query to explore/tags/hashtag/: 404 Not Found [retrying; skip with ^C]
JSON Query to explore/tags/hashtag/: 404 Not Found [retrying; skip with ^C]
Traceback (most recent call last):
  File "/Users/marcus/opt/anaconda3/lib/python3.9/site-packages/instaloader/instaloadercontext.py", line 405, in get_json
    raise QueryReturnedNotFoundException("404 Not Found")
instaloader.exceptions.QueryReturnedNotFoundException: 404 Not Found

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/marcus/opt/anaconda3/lib/python3.9/site-packages/instaloader/instaloadercontext.py", line 405, in get_json
    raise QueryReturnedNotFoundException("404 Not Found")
instaloader.exceptions.QueryReturnedNotFoundException: 404 Not Found

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/marcus/opt/anaconda3/lib/python3.9/site-packages/instaloader/instaloadercontext.py", line 405, in get_json
    raise QueryReturnedNotFoundException("404 Not Found")
instaloader.exceptions.QueryReturnedNotFoundException: 404 Not Found

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

Traceback (most recent call last):
  File "/Users/marcus/Documents/python/instascraper/main.py", line 12, in <module>
    posts = L.get_hashtag_posts('hashtag')
  File "/Users/marcus/opt/anaconda3/lib/python3.9/site-packages/instaloader/instaloader.py", line 1204, in get_hashtag_posts
    return Hashtag.from_name(self.context, hashtag).get_posts_resumable()
  File "/Users/marcus/opt/anaconda3/lib/python3.9/site-packages/instaloader/structures.py", line 1662, in from_name
    hashtag._obtain_metadata()
  File "/Users/marcus/opt/anaconda3/lib/python3.9/site-packages/instaloader/structures.py", line 1676, in _obtain_metadata
    self._node = self._query({"__a": 1, "__d": "dis"})
  File "/Users/marcus/opt/anaconda3/lib/python3.9/site-packages/instaloader/structures.py", line 1671, in _query
    json_response = self._context.get_json("explore/tags/{0}/".format(self.name), params)
  File "/Users/marcus/opt/anaconda3/lib/python3.9/site-packages/instaloader/instaloadercontext.py", line 435, in get_json
    return self.get_json(path=path, params=params, host=host, session=sess, _attempt=_attempt + 1,
  File "/Users/marcus/opt/anaconda3/lib/python3.9/site-packages/instaloader/instaloadercontext.py", line 435, in get_json
    return self.get_json(path=path, params=params, host=host, session=sess, _attempt=_attempt + 1,
  File "/Users/marcus/opt/anaconda3/lib/python3.9/site-packages/instaloader/instaloadercontext.py", line 423, in get_json
    raise QueryReturnedNotFoundException(error_string) from err
instaloader.exceptions.QueryReturnedNotFoundException: JSON Query to explore/tags/hashtag/: 404 Not Found

Any help is appreciated.


Solution

  • Seems like instagram has temporarily blocked your ip Address due to the unusual activity you'd need to change your address or use a quality VPN.