question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Hashtag.from_name(): KeyError: 'graphql'

See original GitHub issue

Found an error given by using wrong json metadata. Tried using different hashtags and to revert to previous versions of Instaloader, but it still gives the problem. I also checked your built-in code and everything looks fine to me, so I suppose it has something to do with Instagram changing it’s metadata format. Maybe this was already fixed for other types of objects but you forgot to fix it for Hashtags (?)

Traceback (most recent call last):
  File "C:\Users\exyss\Desktop\v3.0-beta\src\test.py", line 6, in <module>
    hashtag = instaloader.Hashtag.from_name(_loader.context, "cats")
  File "C:\Users\exyss\AppData\Local\Programs\Python\Python39\lib\site-packages\instaloader\structures.py", line 1302, in from_name
    hashtag._obtain_metadata()
  File "C:\Users\exyss\AppData\Local\Programs\Python\Python39\lib\site-packages\instaloader\structures.py", line 1316, in _obtain_metadata        
    self._node = self._query({"__a": 1})
  File "C:\Users\exyss\AppData\Local\Programs\Python\Python39\lib\site-packages\instaloader\structures.py", line 1311, in _query
    return self._context.get_json("explore/tags/{0}/".format(self.name),
KeyError: 'graphql'

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:23
  • Comments:32 (2 by maintainers)

github_iconTop GitHub Comments

8reactions
aandergrcommented, Nov 12, 2021

Thanks to you all for sharing your observations and for creating such a beautiful collection of workarounds for this issue!

The download of hashtags should now be fixed in Instaloader’s latest pre-release, Version 4.9b1.

5reactions
JoseConicommented, Jul 9, 2021

Here’s a snippet that might elucidate #874 with datetime functionality taken from #121 . It takes posts between dates following a hashtag using the NodeIterator code and stores them in a list.

START = datetime(2021, 5, 28)
END = datetime(2021, 5, 30)
HASHTAG = "<Some Hashtag>"
GraphQL_Hash = "<Some GQL hash>"
posts = []

post_iterator = instaloader.NodeIterator(
    L.context, GraphQL_Hash,
    lambda d: d['data']['hashtag']['edge_hashtag_to_media'],
    lambda n: instaloader.Post(L.context, n),
    {'tag_name': HASHTAG},
    f"https://www.instagram.com/explore/tags/{HASHTAG}/"
)
        
def gen(start, end, posts):
    for post in posts:
        if post.date > start and post.date > end:
            pass
        elif post.date >= start and post.date <= end:
            yield post
        elif post.date <= start:
            break

for post in gen(start=START, end=END, posts=post_iterator):
    posts.append(post)

Hope this helps. Edited for formatting.

What is a “GQL hash”? I did it: er1 And the output was this error: er2 Where can i find the GQL hashtag for my “home” hashtag?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Python+Graphql: KeyError: 'data' recieved upon execution
Error Received. I help a developer out maintaining a simple python script that scrapes images from unsee.cc. I have helped to correct URLs ......
Read more >
redirected to login page. use --login. - You.com | The AI ...
I am trying to download posts and their metadata using Instaloader in Python 3.7. I noticed that for some posts it only returns...
Read more >
model can be defined only once in graphql Code Example
“model can be defined only once in graphql” Code Answer's ... nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use) ·...
Read more >
Trying hashtag.get_recent_posts() get: KeyError: 'graphql'
Hi, trying to get get_recent_posts from Hashtag instance raise this error: ... Trying hashtag.get_recent_posts() get: KeyError: 'graphql'.
Read more >
Error scrapping hashtags - Graphql KeyError - githubmemory
Error scrapping hashtags - Graphql KeyError. ... in __init__(self, tag, sessionid, from_cache) 58 data = self.get_json() 59 cache.make_cache( ---> 60 tag, ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found