Repository: InstaPy/InstaPy

Issue:
KeyError: 'media'
I'm getting this error right before the bot is about to like a post:
`File "/usr/local/lib/python3.6/dist-packages/instapy/instapy.py", line 1914, in like_by_tags self.logger, File "/usr/local/lib/python3.6/dist-packages/instapy/like_util.py", line 606, in check_link media = post_page[0]["media"] KeyError: 'media'`

This is the last step it always reaches:

> .................................................................
> INFO [2019-08-16 12:07:55] [accountname]  Logged in successfully!
> '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
> INFO [2019-08-16 12:07:55] [accountname]  Saving account progress...
> INFO [2019-08-16 12:08:00] [accountname]  Location [1/7]
> INFO [2019-08-16 12:08:00] [accountname]  --> b'213385402/london-united-kingdom'
> INFO [2019-08-16 12:08:11] [accountname]  desired amount: 25  |  top posts [disabled]: 9  |  possible posts: 44373096
> INFO [2019-08-16 12:08:18] [accountname]  Like# [1/25]
> INFO [2019-08-16 12:08:18] [accountname]  https://www.instagram.com/p/B1OO9VTHmlO/
>  
> INFO [2019-08-16 12:08:24] [accountname]  Sessional Live Report:
>     |> No any statistics to show
>  
> On session start was FOLLOWING xxx users & had xxx FOLLOWERS
> [Session lasted 1.77 minutes]
>  
> OOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO
> INFO [2019-08-16 12:08:24] [accountname]  Session ended!
> oooooooooooooooooooooooooooooooooooooooooooooooooooooooo


If anybody has an idea about what's going on I'll be very grateful 


Discussion:
I have the same problem, but I've got some sort of idea why this is happening. `post_page` is equal to `[{}]` for some reason. Logs:
```
OOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO
INFO [2019-08-17 12:39:49] [username]  Session started!
oooooooooooooooooooooooooooooooooooooooooooooooooooooo
C:\Users\Quinten\InstaPy\logs\username\relationship_data
INFO [2019-08-17 12:39:49] [username]  -- Connection Checklist [1/3] (Internet Connection Status)
INFO [2019-08-17 12:39:49] [username]  - Internet Connection Status: ok
INFO [2019-08-17 12:39:49] [username]  - Current IP is "X.X.X.X" and it's from "United States/US"
INFO [2019-08-17 12:39:49] [username]  -- Connection Checklist [2/3] (Instagram Server Status)
INFO [2019-08-17 12:39:55] [username]  - Instagram WebSite Status: Currently Up 
INFO [2019-08-17 12:39:55] [username]  - Instagram Response Time: 112.239 ms 
INFO [2019-08-17 12:39:55] [username]  - Instagram Reponse Code: 200
INFO [2019-08-17 12:39:55] [username]  - Instagram Server Status: ok
INFO [2019-08-17 12:39:55] [username]  -- Connection Checklist [3/3] (Hide Selenium Extension)
INFO [2019-08-17 12:39:55] [username]  - window.navigator.webdriver response: False
INFO [2019-08-17 12:39:55] [username]  - Hide Selenium Extension: ok
```
The second to last line, `window.navigator.webdriver response: False` is what's causing issues I think. If I had to guess, there was a change in how the json parser works which results `post_page` being set to what it is. What's odd though, is that `post_page` is supposed to [return](https://github.com/timgrossmann/InstaPy/blob/dev/instapy/like_util.py#L570) when it is set to `None`, so I don't know why there is an error being thrown beyond that point.
OK, so after further inspection, when viewing the source code for a post I was monitoring, the `post_page` element of the json file actually equals `[{}]`...I have no idea where to go from here.
Thanks for the hints. I'm still trying to fix it but nothing yet...
Same issue.
I have the same problem. 
same problem
I have the same problem
After a little investigation (and I'm not familiar with what the old format was) it looks like `window._sharedData.entry_data` was removed in favor of `window.__additionalData`. 
Similar to https://github.com/timgrossmann/InstaPy/pull/4892 it looks like some references need to be updated.

Specifically something like this: https://github.com/timgrossmann/InstaPy/pull/4892/files#diff-870c589a51f82fb50caf6a78df9e4273R1576

Resolving patch:
diff --git a/instapy/like_util.py b/instapy/like_util.py
--- a/instapy/like_util.py
+++ b/instapy/like_util.py
@@ -552,7 +552,7 @@ def check_link(
     # Check if the Post is Valid/Exists
     try:
         post_page = browser.execute_script(
-            "return window._sharedData.entry_data.PostPage"
+            "return window.__additionalData[Object.keys(window.__additionalData)[0]].data"
         )
 
     except WebDriverException:  # handle the possible `entry_data` error
@@ -561,7 +561,7 @@ def check_link(
             update_activity(browser, state=None)
 
             post_page = browser.execute_script(
-                "return window._sharedData.entry_data.PostPage"
+                "return window.__additionalData[Object.keys(window.__additionalData)[0]].data"
             )
 
         except WebDriverException:
@@ -572,9 +572,9 @@ def check_link(
         return True, None, None, "Unavailable Page", "Failure"
 
     # Gets the description of the post's link and checks for the dont_like tags
-    graphql = "graphql" in post_page[0]
+    graphql = "graphql" in post_page
     if graphql:
-        media = post_page[0]["graphql"]["shortcode_media"]
+        media = post_page["graphql"]["shortcode_media"]
         is_video = media["is_video"]
         user_name = media["owner"]["username"]
         image_text = media["edge_media_to_caption"]["edges"]
@@ -585,8 +585,8 @@ def check_link(
         # double {{ allows us to call .format here:
         owner_comments = browser.execute_script(
             """
-            latest_comments = window._sharedData.entry_data.PostPage[
-            0].graphql.shortcode_media.{}.edges;
+            latest_comments = window.__additionalData[Object.keys(window.__additionalData)[0]];
+            latest_comments = latest_comments.data.graphql.shortcode_media.{}.edges;
             if (latest_comments === undefined) {{
                 latest_comments = Array();
                 owner_comments = latest_comments
@@ -802,12 +802,12 @@ def get_tags(browser, url):
     web_address_navigator(browser, url)
 
     graphql = browser.execute_script(
-        "return ('graphql' in window._sharedData.entry_data.PostPage[0])"
+        "return ('graphql' in window.__additionalData[Object.keys(window.__additionalData)[0]].data)"
     )
 
     if graphql:
         image_text = browser.execute_script(
-            "return window._sharedData.entry_data.PostPage[0].graphql."
+            "return window.__additionalData[Object.keys(window.__additionalData)[0]].data.graphql."
             "shortcode_media.edge_media_to_caption.edges[0].node.text"
         )
 
@@ -866,9 +866,8 @@ def verify_liking(browser, maximum, minimum, logger):
     & minimum values defined by user """
     try:
         likes_count = browser.execute_script(
-            "return window._sharedData.entry_data."
-            "PostPage[0].graphql.shortcode_media.edge_media_preview_like"
-            ".count"
+            "return window.__additionalData[Object.keys(window.__additionalData)[0]].data"
+            ".graphql.shortcode_media.edge_media_preview_like.count"
         )
 
     except WebDriverException:


Test patch: