Instapy: Regular Crashes - Unknown error: Cannot read property 'entry_data' of undefined

Created on 2 Feb 2018  ·  60Comments  ·  Source: timgrossmann/InstaPy

Running latest version of chrome driver/chrome/Instapy.
Standard configuration (just likes/comments by hashtag).

Crashes every 10-15 minutes with this message:
1

wontfix

Most helpful comment

uluQulu's comment absolutely fixed the problem I had with the latest commit of InstaPy. Thank you so much!

All 60 comments

Sometimes latest versions of chromedriver, GoogleChrome and selenium are incompatible..
Start by downgrading Google Chrome to previous working version _and disable automatic updates_, maybe it's the problem..
_In Windows 10, I'm still using Google Chrome v62 without problems_

Aha, I did not know that! Will give it a try. Which chrome driver version do you use with v62? I have this issue all the time, will try downgrading to 62

Greetings! getting exactly the same error at random intervals. Love the program but the error is very annoying because I have to restart every twenty minutes. Just doing basic following, liking, commenting, nothing fancy

Will try that tonight!

@ArdySan2012
ChromeDriver 2.34.522940
Google Chrome Version 62.0.3202.62 (Official Build) (64-bit)
Selenium Version 3.8.1

@Tachenz
For some non-specific policital reasons installing an old version of Google Chrome is a big pain, so is disabling it's updates..
Here I included some helpful links I used last time,
There are a few websites share old Google Chromes,
FilePuma
Slimjet
_(Google doesn't offer old version officially or inofficially)_

To disable Google Chrome updates see:
Read instructions (Google official paper)
Download Group Policies from Google

from there, you must download Administrative Template XML-based (ADMX) file - it is a Policy template to be added to gpedit.msc in order to disable Google Updates from policies..

Be sure to check executables at Virus Total before installing

_Personally,
I did disable Google Chrome updates from Group Policy, Registry and also did reset CLSID to zero in "Help, about Chrome" which will ask for privileges and if succeds elevation can/will UPDATE. I also blocked Google Update files (C:\Program Files(x86)\Google*update*) from Firewall._
This is also helpful read

Thank you @uluQulu ! I've just renamed the GoogleUpdate.exe file in C:\Program Files(x86)\Googleupdate folder :) And disable google update service. Stays v62 for now. Launching the script and we will see if that helps.. (fingers chrossed)

@uluQulu Unfortunately the same error still persists with version 62 as well...
untitled2

It crashes with 62.032 version of chrome. Browser displays that “Sorry, something went wrong message”

Tried with 2.34 and 2.33 chrome driver versions. Same story. Can somebody help pretty please?

Same error occurs in raspberry pi3 running firefox. It typically happens once a day for each account I run.

It's weird, I have not run into this problem. Maybe it's because I don't run that much..
@Tachenz can you fetch the data from Chrome to inspect?
just copy pic link from somebody's picture and paste in adress bar and press enter and right click _inspect_ it,
find window._sharedData and copy everything in it, I wonder what could be changed since it happens so frequently in your side..
Maybe Instagram has changed something to test for some users..
Also if you could fetch inspection data from the same picture link where error occured would be awesome

window._sharedData will not have the entry_data if not reached directly from url.
If got there from tag clicking on username it will not be there .

Will try do that soon! Would it help if I gather this info from the chrome page with that error (when this crash happens - page displays "Sorry something went wrong - we are working to fix this"). Or should I do just random insta photo in non-automatically opened chrome window from Instagram?

I sometimes have long runs without this error (I run on WAY slower speed, maybe 30-40 actions per hour), but sometimes it just happens every hour or so. Can't tie it to anything really.

So this is window shared data while the script was waiting/sleeping on one of the photos
PS thank you @uluQulu for looking into it!

window._sharedData = {"activity_counts":{"comment_likes":7,"comments":2,"likes":3,"relationships":1,"usertags":0},"config":{"csrf_token":"_________","viewer":{""_______","profile_pic_url_hd":"_____","username":"_______"}},"country_code":"_____","language_code":"en","locale":"en_US","entry_data":{"PostPage":[{"graphql":{"shortcode_media":{"__typename":"GraphSidecar","id":"1707258385491124640","shortcode":"BexZnTHAWGg","dimensions":{"height":1080,"width":1080},"gating_info":null,"media_preview":null,"display_url":"https://scontent-lhr3-1.cdninstagram.com/vp/712464c37ef570c92267b96c8d84edea/5B0C5ECE/t51.2885-15/e35/26869661_216830938864848_6974877737374711808_n.jpg","display_resources":[{"src":"https://scontent-lhr3-1.cdninstagram.com/vp/96ac3159a4f40bfb1a1b894f41ad3ccb/5B04C7AF/t51.2885-15/s640x640/sh0.08/e35/26869661_216830938864848_6974877737374711808_n.jpg","config_width":640,"config_height":640},{"src":"https://scontent-lhr3-1.cdninstagram.com/vp/c4f7b2d118193bed0188538537da5f42/5B238882/t51.2885-15/s750x750/sh0.08/e35/26869661_216830938864848_6974877737374711808_n.jpg","config_width":750,"config_height":750},{"src":"https://scontent-lhr3-1.cdninstagram.com/vp/712464c37ef570c92267b96c8d84edea/5B0C5ECE/t51.2885-15/e35/26869661_216830938864848_6974877737374711808_n.jpg","config_width":1080,"config_height":1080}],"is_video":false,"should_log_client_event":false,"tracking_token":"eyJ2ZXJzaW9uIjo1LCJwYXlsb2FkIjp7ImlzX2FuYWx5dGljc190cmFja2VkIjpmYWxzZSwidXVpZCI6IjY2OTZhOTA1OWUxYjRiZjZhZjk0ZjFiYzE4OWRlYmMxMTcwNzI1ODM4NTQ5MTEyNDY0MCIsInNlcnZlcl90b2tlbiI6IjE1MTc3NTAxMDAxMzl8MTcwNzI1ODM4NTQ5MTEyNDY0MHwxODI2Mzc4MTR8NmUxZWRkYjI1ZjRmYmNlNGVlMWQzNWE0NWU5N2U1MTczYzk4Zjg0NTdlMWZjMjk1NTE5YzBmZjQyM2ViYzRlOCJ9LCJzaWduYXR1cmUiOiIifQ==","edge_media_to_tagged_user":{"edges":[]},"edge_media_to_caption":{"edges":[{"node":{"text":"Acordate los estacionamos junto al Bridge! #sydney #operahouse #sydneyharbourbridge"}}]},"caption_is_edited":false,"edge_media_to_comment":{"count":0,"page_info":{"has_next_page":false,"end_cursor":null},"edges":[]},"comments_disabled":false,"taken_at_timestamp":1517741080,"edge_media_preview_like":{"count":6,"edges":[{"node":{"id":"505670828","profile_pic_url":"https://scontent-lhr3-1.cdninstagram.com/vp/4dc7a4e487eda637e61290a56f04d22f/5B1A600E/t51.2885-19/s150x150/14262684_692096734280580_1009890534_a.jpg","username":"wliebh"}},{"node":{"id":"3184653118","profile_pic_url":"https://scontent-lhr3-1.cdninstagram.com/vp/58340515153b980b15717f316043b799/5B19EEA1/t51.2885-19/s150x150/12976684_538584266326625_1206713872_a.jpg","username":"maia_wiernik"}},{"node":{"id":"1436887521","profile_pic_url":"https://scontent-lhr3-1.cdninstagram.com/vp/0feb6390ac94978612e5c7db714896d2/5B0009BA/t51.2885-19/s150x150/21294531_270724069999094_2497131700002226176_a.jpg","username":"caro.gerchkovich"}},{"node":{"id":"1118879371","profile_pic_url":"https://scontent-lhr3-1.cdninstagram.com/vp/f1f3750de68b7c39740d00c92b717705/5B02E31A/t51.2885-19/11875267_397035670485958_1407314053_a.jpg","username":"nellysued"}},{"node":{"id":"232872700","profile_pic_url":"https://scontent-lhr3-1.cdninstagram.com/vp/421f3130b61650cb085321daca464f4e/5B113E2E/t51.2885-19/11809882_106638613021680_2066950471_a.jpg","username":"yaninasp"}},{"node":{"id":"5605899588","profile_pic_url":"https://scontent-lhr3-1.cdninstagram.com/vp/e24f4f690261c0326f13baa170ed9e52/5B1C5332/t51.2885-19/s150x150/21042084_287859198360726_9027867298794307584_a.jpg","username":"lindusdrycleaners"}}]},"edge_media_to_sponsor_user":{"edges":[]},"location":{"id":"166140513986814","has_public_page":true,"name":"Sydney Harbour Bridge","slug":"sydney-harbour-bridge"},"viewer_has_liked":false,"viewer_has_saved":false,"viewer_has_saved_to_collection":false,"owner":{"id":"1138354285","profile_pic_url":"https://scontent-lhr3-1.cdninstagram.com/vp/c439a92ccc2bf76232cefd3756eefce2/5B04375E/t51.2885-19/s150x150/18948160_137897090110508_890353751322263552_a.jpg","username":"fekaus","blocked_by_viewer":false,"followed_by_viewer":false,"full_name":"Fede Kaus","has_blocked_viewer":false,"is_private":false,"is_unpublished":false,"is_verified":false,"requested_by_viewer":false},"is_ad":false,"edge_web_media_to_related_media":{"edges":[]},"edge_sidecar_to_children":{"edges":[{"node":{"__typename":"GraphImage","id":"1707258121266894175","shortcode":"BexZjdCA5Vf","dimensions":{"height":1080,"width":1080},"gating_info":null,"media_preview":null,"display_url":"https://scontent-lhr3-1.cdninstagram.com/vp/712464c37ef570c92267b96c8d84edea/5B0C5ECE/t51.2885-15/e35/26869661_216830938864848_6974877737374711808_n.jpg","display_resources":[{"src":"https://scontent-lhr3-1.cdninstagram.com/vp/96ac3159a4f40bfb1a1b894f41ad3ccb/5B04C7AF/t51.2885-15/s640x640/sh0.08/e35/26869661_216830938864848_6974877737374711808_n.jpg","config_width":640,"config_height":640},{"src":"https://scontent-lhr3-1.cdninstagram.com/vp/c4f7b2d118193bed0188538537da5f42/5B238882/t51.2885-15/s750x750/sh0.08/e35/26869661_216830938864848_6974877737374711808_n.jpg","config_width":750,"config_height":750},{"src":"https://scontent-lhr3-1.cdninstagram.com/vp/712464c37ef570c92267b96c8d84edea/5B0C5ECE/t51.2885-15/e35/26869661_216830938864848_6974877737374711808_n.jpg","config_width":1080,"config_height":1080}],"is_video":false,"should_log_client_event":false,"tracking_token":"eyJ2ZXJzaW9uIjo1LCJwYXlsb2FkIjp7ImlzX2FuYWx5dGljc190cmFja2VkIjpmYWxzZSwidXVpZCI6IjY2OTZhOTA1OWUxYjRiZjZhZjk0ZjFiYzE4OWRlYmMxMTcwNzI1ODEyMTI2Njg5NDE3NSIsInNlcnZlcl90b2tlbiI6IjE1MTc3NTAxMDAxNDd8MTcwNzI1ODEyMTI2Njg5NDE3NXwxODI2Mzc4MTR8ZmM0OTExYzU2MGMwOTRmODE1YzQ4ZjE1ODYwNDY3NGE2Mzg0YTBiNDk5MDY5OTA5NzI0YzBjZDE5MTMzMjUwMCJ9LCJzaWduYXR1cmUiOiIifQ==","edge_media_to_tagged_user":{"edges":[]}}},{"node":{"__typename":"GraphImage","id":"1707258194382011982","shortcode":"BexZkhIA75O","dimensions":{"height":1080,"width":1080},"gating_info":null,"media_preview":null,"display_url":"https://scontent-lhr3-1.cdninstagram.com/vp/f5cc090127ae9c6f5f004c465b0e68f8/5B02AEDB/t51.2885-15/e35/26863339_892656364402762_3886300324561944576_n.jpg","display_resources":[{"src":"https://scontent-lhr3-1.cdninstagram.com/vp/84cc36f1b84a264d7c93cc7b8db929ad/5B047CBA/t51.2885-15/s640x640/sh0.08/e35/26863339_892656364402762_3886300324561944576_n.jpg","config_width":640,"config_height":640},{"src":"https://scontent-lhr3-1.cdninstagram.com/vp/129e1446b07e79fd838a35f5c0e7fbf2/5B149397/t51.2885-15/s750x750/sh0.08/e35/26863339_892656364402762_3886300324561944576_n.jpg","config_width":750,"config_height":750},{"src":"https://scontent-lhr3-1.cdninstagram.com/vp/f5cc090127ae9c6f5f004c465b0e68f8/5B02AEDB/t51.2885-15/e35/26863339_892656364402762_3886300324561944576_n.jpg","config_width":1080,"config_height":1080}],"is_video":false,"should_log_client_event":false,"tracking_token":"eyJ2ZXJzaW9uIjo1LCJwYXlsb2FkIjp7ImlzX2FuYWx5dGljc190cmFja2VkIjpmYWxzZSwidXVpZCI6IjY2OTZhOTA1OWUxYjRiZjZhZjk0ZjFiYzE4OWRlYmMxMTcwNzI1ODE5NDM4MjAxMTk4MiIsInNlcnZlcl90b2tlbiI6IjE1MTc3NTAxMDAxNTB8MTcwNzI1ODE5NDM4MjAxMTk4MnwxODI2Mzc4MTR8NTMwZDhjNjViY2Q1YjhmOWFhNDUzN2RmMmZjMTFjNTdjOTAzOThjNzc2Y2E2NGNlODI0ZjUwMmRiMmQ4ZTcyZSJ9LCJzaWduYXR1cmUiOiIifQ==","edge_media_to_tagged_user":{"edges":[]}}},{"node":{"__typename":"GraphImage","id":"1707258235368542691","shortcode":"BexZlHTAJHj","dimensions":{"height":1080,"width":1080},"gating_info":null,"media_preview":null,"display_url":"https://scontent-lhr3-1.cdninstagram.com/vp/2270cc822d07a678af9c7a195b595f1f/5B259A33/t51.2885-15/e35/26866425_414406202326968_4034770871468949504_n.jpg","display_resources":[{"src":"https://scontent-lhr3-1.cdninstagram.com/vp/32816071eeb4c33c478edc4e369b5b93/5B052452/t51.2885-15/s640x640/sh0.08/e35/26866425_414406202326968_4034770871468949504_n.jpg","config_width":640,"config_height":640},{"src":"https://scontent-lhr3-1.cdninstagram.com/vp/2e5ad3d5bce993839ef0510aff3eeb0c/5B1F7F7F/t51.2885-15/s750x750/sh0.08/e35/26866425_414406202326968_4034770871468949504_n.jpg","config_width":750,"config_height":750},{"src":"https://scontent-lhr3-1.cdninstagram.com/vp/2270cc822d07a678af9c7a195b595f1f/5B259A33/t51.2885-15/e35/26866425_414406202326968_4034770871468949504_n.jpg","config_width":1080,"config_height":1080}],"is_video":false,"should_log_client_event":false,"tracking_token":"eyJ2ZXJzaW9uIjo1LCJwYXlsb2FkIjp7ImlzX2FuYWx5dGljc190cmFja2VkIjpmYWxzZSwidXVpZCI6IjY2OTZhOTA1OWUxYjRiZjZhZjk0ZjFiYzE4OWRlYmMxMTcwNzI1ODIzNTM2ODU0MjY5MSIsInNlcnZlcl90b2tlbiI6IjE1MTc3NTAxMDAxNTR8MTcwNzI1ODIzNTM2ODU0MjY5MXwxODI2Mzc4MTR8YmNhZGRkMWM1OGQxODYyNDdjZGMwOTQ5ZGU1ODZkZjkyNDQ4YmRiZmMyN2M2NDJkMjlkZjIzYWNlOWViNTI2NSJ9LCJzaWduYXR1cmUiOiIifQ==","edge_media_to_tagged_user":{"edges":[]}}}]}}}}]},"gatekeepers":{"ld":true,"sms":true,"vl":true,"unb":true,"rst":true,"seo":true},"qe":{"dash_for_vod":{"g":"","p":{}},"bc3l":{"g":"control","p":{"threeline":"false"}},"aysf":{"g":"","p":{}},"notif":{"g":"","p":{}},"follow_button":{"g":"test","p":{"is_inline":"true"}},"login_via_signup_page":{"g":"test","p":{"is_enabled":"true"}},"loggedout":{"g":"test","p":{"new_cta":"true","remove_upsell_banner":"true","update_nav":"true"}},"stories":{"g":"","p":{}},"exit_story_creation":{"g":"","p":{}},"su_universe":{"g":"control_msisdn_prefill_12_18","p":{"has_msisdn_prefill":"false"}},"us_li":{"g":"Control","p":{"show_related_media":"false"}},"sidecar":{"g":"","p":{}},"video":{"g":"","p":{}},"filters":{"g":"","p":{}},"appsell":{"g":"","p":{}},"collections":{"g":"","p":{}},"save":{"g":"test","p":{"is_enabled":"true"}},"stale":{"g":"","p":{}},"reg":{"g":"new_reg_with_appsells_01_10","p":{"has_new_landing_appsells":"true","has_new_landing_page":"true"}},"reg_vp":{"g":"control_group_1","p":{"hide_value_prop":"false"}},"prof_pic_upsell":{"g":"","p":{}},"prof_pic_creation":{"g":"test_01_02","p":{"enable_asyncio":"true"}},"onetaplogin":{"g":"","p":{}},"feed_vp":{"g":"launch","p":{"is_hidden":"true"}},"push_notifications":{"g":"","p":{}},"login_poe":{"g":"","p":{}},"report_haf":{"g":"","p":{}},"report_profile":{"g":"","p":{}},"reporting":{"g":"control","p":{"profile_report_confirmation_enabled":"false"}},"a2hs":{"g":"test","p":{"is_enabled":"true"}},"bg_sync":{"g":"","p":{}},"disc_ppl":{"g":"test_12_14","p":{"is_enabled":"true"}},"ebdsim_li":{"g":"","p":{}},"ebdsim_lo":{"g":"","p":{}},"embeds":{"g":"","p":{}},"prvcy_tggl":{"g":"","p":{}},"v_grid":{"g":"","p":{}},"tp_pblshr":{"g":"","p":{}},"fs":{"g":"","p":{}},"404_as_react":{"g":"","p":{}},"share":{"g":"","p":{}}},"hostname":"www.instagram.com","display_properties_server_guess":{"pixel_ratio":1.0,"viewport_width":1034,"viewport_height":576,"orientation":"landscape-primary"},"environment_switcher_visible_server_guess":true,"platform":"web","nonce":"SHT5EUqp2k14QYYSMESCgA==","zero_data":{},"rollout_hash":"dfbbbf40a190","probably_has_app":true,"show_app_install":false};

At output above"entry_data":{"PostPage" means it is okay,
one more question @Tachenz
when this error occurs, does it always stuck at the _Sorry, something went wrong._ screen?

@uluQulu yes, always “sorry, something went wrong”.
It also always happens on the initial picture load (never on like/follow or comment step).

Also, if I just press F5 on that chrome page, - it loads normally.

So I was wondering. Is there a quick and dirty fix to try to search for those words before throwing an error and if found - send F5 to simply refresh the page?

thanks @ArdySan2012 for great mentions, it's clear now

Supposedly, my thoughts are
It's clear that, "Cannot read property 'entry_data' of undefined" is pointing the issue that "Instagram page is not properly loaded."
_entry_data belongs to instagram, when page is not loaded it cannot execute script_

you can test it by navigating to any non-instagram website, opening dev tools, running window._sharedData.entry_data.PostPage in console, _you would see the same WebDriverException (a browser exception) error,
but if it could navigate to the Instagram page, and would not find PostPage, it would just return 'undefined' (None) value instead of WebDriverException, cos entry_data still exists there with another variable, like FeedPage, TagPage, LocationPage, etc.

I also don't think it is Selenium issue, cos it doesn't happen in many users with same versions, also as you tested other Chrome & chromedriver versions (also Firefox deals with same), supposedly it is not the issue too..
For me, it's in Facebook server side after new beta changes to Instagram configuration (in test),

Solution: temporarily, you can catch this error and continue the program run without a break,
in check_link function at like_util.py,
import WebDriverException:

from selenium.common.exceptions import WebDriverException

and replace lines 415 & 416 with:

try:
    post_page = browser.execute_script(
        "return window._sharedData.entry_data.PostPage")
except WebDriverException:
    try:
        #refresh page (you would refresh twice (or more), too) and try again
        #browser.get(link)  #method 1, when page is not loaded properly, it is not expected to reload. use this to navigate to first (use if method 2 didn't work)
        browser.execute_script("location.reload()")   #mehod 2, simple refresh - page loaded properly, can be reloaded
        post_page = browser.execute_script(
            "return window._sharedData.entry_data.PostPage")
    except WebDriverException:
        post_page = None   #quit trying, cos page is really break

I've added two layers of try/except block, just to be sure page is not broken really and if it is, assigned post_page a None value

DETAILS
This is famous Facebook error (not Instagram specific) issuing a temporary outage
As FB announced about changes in operating Instagram API, which affects all and every plugin and service using Instagram data, earlier this month many people had trouble accessing posts in Instagram.
This was not the result of a latest commit but instead occurred after they introduced a change that affected their configuration systems
And they, as usual, is testing some new stuff in some users at specific areas, that's why we haven't seen that error, yet
I think it's temporary and after they fix the problem, and service is back to 100% for everyone
@Tachenz @gitpatrickhub @Wisdomlocker
Hope it helped :-)

Going to try this right now!! Sorry, which lines are to be replaced exactly? As we've changed the line numbering adding import WebDriverException
These ones, right?
post_page = browser.execute_script(
"return window._sharedData.entry_data.PostPage")

@Tachenz
sorry I didn't count that import line xD
so choose lines before importing it
yes exactly, modify that post_page variable's place

Yep - that works!
Not sure if instagram changed something at the same time or it is related to this fix - but now bot, while clearly scrolling through a lot of pictures - starts in 1/27 mode and does 27 only...

@uluQulu was able to paste the lines, but can not check if it fixed it :) Having this issue now - https://github.com/timgrossmann/InstaPy/issues/1365 (Script basically would not load more than few images per go, anywhere from 12-30 only - no matter how many in settings...

I don't think those poor lines could cause this new issue
@Tachenz mentioned that issue, those guys did not paste those fix lines xD
actually, what this fix doing is just handling WebDriverException while finding PostPage entry..

similarly, if WebDriverException could happen elsewhere than our fixed lines, it would return that same error and simply quit

@ArdySan2012
I'll try to have a look at that issue, got some hints already..
~ Instagram definitely changed something :/

@uluQulu For now I am running a sequence of 10 hashtags, repeated over and over again (it does 27 of each), and the old "undefined" error nowhere to be seen for now! Kudos to you!!

As for the loading, yep - Instagram just loves messing with itself :D

@uluQulu Ooops, sorry. That error again happened. Apparently another exception occured while trying to handle the old one ('webdriver' object has no attribute location):
untitled

@uluQulu @ArdySan2012 Same for me! Only 27 images are loaded each tag. When using the follow action it behaves normally and uses the specified amount.
27 images on the normal desktop browser mean 9 rows of images. Maybe the scrolling is happening too fast?
Could someone open an extra issue to keep this issue focused on @Tachenz crash problem?

Phew! I forgot execute_script :|
so in the fix lines,
instead of

browser.location.reload()

put

browser.execute_script("location.reload()")

@Tachenz I'm really sorry, I just forgot it's not a browser console xD
@ArdySan2012 apply this update, mate

Where are you guys from, I wonder the area you are (or your proxies are set to)..
cos I think FB is testing its new Instagram updates on some specific areas (as they did previously in history), to say, the US or western Europas..
But also they may have new strategy testing stuff...

I am in UK. And it has been on and off for about a month now (but really inconsistently - sometimes a whole day without it, sometimes - every hour). It does feel like facebook side related...
Running the “location” version now, fingers crossed! :)

@uluQulu Unfortunately it is still happening :( The undefined error, after I've updated with "location.reload"
1111

As if after that it just ignored the fix...

@uluQulu thanks for your input, I also followed through with your suggestions and the error unfortunately still happens. Look forward to other creative solutions from you!

_see_ UPDATED solution here

OLD solution:
Wow @Tachenz I thought this is a new error, but it's not :-D
Previously, we've handled the error in line 416 (see your previous error screen shot above, it says)
but now it is pointing out line 494, it's a new line, which that entry_data error would happen too, and it actually happened in one of the guys in our Slack channel, and I told him to fix that line specifically (as you dealt with 416 first, he faced line 494 instead..)
but now I see that you get both of those errors, they are very identical same sort of errors, and you must handle it as we did in previous line of 416,

Fix is similar, near line of 494 in like_util.py
find line of

num_followers = browser.execute_script(
            "return window._sharedData.entry_data."
            "ProfilePage[0].user.followed_by.count")

and replace it with

try:
    num_followers = browser.execute_script(
        "return window._sharedData.entry_data."
        "ProfilePage[0].user.followed_by.count")
except WebDriverException:
    try:
        browser.execute_script("location.reload()")
        num_followers = browser.execute_script(
            "return window._sharedData.entry_data."
            "ProfilePage[0].user.followed_by.count")
    except WebDriverException:
        num_followers = 'undefined'
        like_by_followers_lower_limit = None
        like_by_followers_upper_limit = None

actually, I thought about telling you of fixing this part too, but I forgot, somehow...

finally, I think this is the last error handling cos I have neither heard of any other entry_data error in the community yet, nor expect from code patterns..

_Hey @Wisdomlocker feel free to use these fixes, that's all I can do for @Tachenz and some other guys who do appreciate it :-)_

@uluQulu Appreciate it very much indeed! Going to try this one now!

It works very well for now! How do we let @timgrossmann to add this solution to the main files? :)

But shell we handle it for each entry_data separetly?
Maybe we fixing the simpton but not the real problem?

@sionking
to be honest, I think this error is temporary and will continue to appear until Facebook ends up with stable configuration (if it does)
late yesterday, it hit my connection too, but in different place- while logging in (once executed script in print_log_writer.py) and I handled followed_by variable in there, too

then also inspected that error's page and pastebinned here to have a detailed look...

funnily it is almost empty and is a Facebook webpage rather than Instagram

@uluQulu There is nothing more permanent than temporary, especially when it comes to Facebook bugs :))

That said, after couple days, fix is still holding quite well. It may crash in some random space, but during the photo load was the most frequent one. Thanks for dealing with that one!

@uluQulu I wanted to thank you for your help. I have also used your proposed solution and I have not had any trouble since. It's great to have you in this group!!!

@uluQulu Hey hey there! When you fixed that, was the fix tied to exact content of that error page?

Because it now seems, that the error is back - and where we were getting "Facebook error" is just the line of text "Oops, something went wrong". Simple F5 refresh deals with it, but bot throws old good "cannot read property error".. Caught it once today, testing some more to do screenshots...

@Tachenz
That error did happen once we queried entry_data content and in entire instapy files there are only 3 places that deal with this.
Which fix are you using? There is a merged commit that did cover 2 of those places (graphql approach) and then my this approach (catch exception + reload + recheck). Now which way you are using to handle this problem?

If you have updated your files with master you ARE most probably using the other way, not this fix

@uluQulu And you are right as always while applying the fix to the new bot version (old one started crashing) - I've just done the Part A of the fix, forgetting we had Part B below. Adjusted that, hopefully it will take care of it!
What do we need to do for these changes to make it into the main version? Vote it up? :)

Haven't understood you @Tachenz I'm sorry

Was just saying that neither of two fixes:

try:
    post_page = browser.execute_script(
        "return window._sharedData.entry_data.PostPage")
except WebDriverException:
    try:
        #refresh page (you would refresh twice (or more), too) and try again
        #browser.get(link)  #method 1, when page is not loaded properly, it is not expected to reload. use this to navigate to first (use if method 2 didn't work)
        browser.execute_script("location.reload()")   #mehod 2, simple refresh - page loaded properly, can be reloaded
        post_page = browser.execute_script(
            "return window._sharedData.entry_data.PostPage")
    except WebDriverException:
        post_page = None   #quit trying, cos page is really break

nor

try:
    num_followers = browser.execute_script(
        "return window._sharedData.entry_data."
        "ProfilePage[0].user.followed_by.count")
except WebDriverException:
    try:
        browser.execute_script("location.reload()")
        num_followers = browser.execute_script(
            "return window._sharedData.entry_data."
            "ProfilePage[0].user.followed_by.count")
    except WebDriverException:
        num_followers = 'undefined'
        like_by_followers_lower_limit = None
        like_by_followers_upper_limit = None

are in the main version of the script (and I forgot about the second one while updating)

@Tachenz
Have you seen the new approach to handle this problem which was also merged recently in #1610? (_although it didn't cover handling post_page query_)

Meanwhile our approach in this post is still working flawlessly, also, I did not write it for a PR, but for helping you out :)

Oh, I have not seen that one, no :) And thank you for help!

PS @uluQulu But #1610 was PRed 10 day ago. So I had this problem with it (and in that topic some people still having trouble). Your solution is better :D

uluQulu's comment absolutely fixed the problem I had with the latest commit of InstaPy. Thank you so much!

@Tachenz during some tests with the up-to-date main repo files without my modifications, I've also just faced that issue in line 498 of like_util.py where num_followers variable resides _which_ was fixed with graphql approach in #1610
Impressed, cos I thought @CharlesCCC's approach did fully solve the issue but I think the problem with these particular entry_data queries is exactly the temporary outage from the FB servers _for some reasons_ and it will continue to happen (_until it is fixed in the server-side_) regardless of the method of getting the data (whether graphql or legacy) and the solution from #1338 will stand joyously unrestrained on the go 🔭 (_multi-checks the existence/absence of data on reloads_)

Gentlemen,
just cloned (for the third time in two days, just to avoid you ask me again if I run the latest) InstaPy on my CentOS 7 VPS, Google Chrome v65.0.3325, chromedriver v2.37. I applied the fix for scrolling more than 27 images (see #1365) by @uluQulu .
The result is this (please note that about two weeks ago I did not have any issue while running even 100 images per tag):

Traceback (most recent call last):
  File "quickstart.py", line 38, in <module>
    session.like_by_tags(['racing'], amount=50)
  File "/home/user/InstaPy/instapy/instapy.py", line 890, in like_by_tags
    self.logger)
  File "/home/user/InstaPy/instapy/like_util.py", line 482, in check_link
    "return window._sharedData.entry_data."
  File "/usr/lib/python2.7/site-packages/selenium/webdriver/remote/webdriver.py", line 627, in execute_script
    'args': converted_args})['value']
  File "/usr/lib/python2.7/site-packages/selenium/webdriver/remote/webdriver.py", line 312, in execute
    self.error_handler.check_response(response)
  File "/usr/lib/python2.7/site-packages/selenium/webdriver/remote/errorhandler.py", line 242, in check_response
    raise exception_class(message, screen, stacktrace)
**selenium.common.exceptions.WebDriverException: Message: unknown error: Cannot read property 'followed_by' of undefined**
  (Session info: headless chrome=65.0.3325.181)
  (Driver info: chromedriver=2.37.544315 (730aa6a5fdba159ac9f4c1e8cbc59bf1b5ce12b7),platform=Linux 3.10.0-693.21.1.el7.x86_64 x86_64)

So I have been suggested to look here and apply the fix
Same issue again:

Traceback (most recent call last):
  File "quickstart.py", line 38, in <module>
    session.like_by_tags(['racing'], amount=50)
  File "/home/user/InstaPy/instapy/instapy.py", line 890, in like_by_tags
    self.logger)
  File "/home/user/InstaPy/instapy/like_util.py", line 493, in check_link
    "return window._sharedData.entry_data."
  File "/usr/lib/python2.7/site-packages/selenium/webdriver/remote/webdriver.py", line 627, in execute_script
    'args': converted_args})['value']
  File "/usr/lib/python2.7/site-packages/selenium/webdriver/remote/webdriver.py", line 312, in execute
    self.error_handler.check_response(response)
  File "/usr/lib/python2.7/site-packages/selenium/webdriver/remote/errorhandler.py", line 242, in check_response
    raise exception_class(message, screen, stacktrace)
**selenium.common.exceptions.WebDriverException: Message: unknown error: Cannot read property 'followed_by' of undefined**
  (Session info: headless chrome=65.0.3325.181)
  (Driver info: chromedriver=2.37.544315 (730aa6a5fdba159ac9f4c1e8cbc59bf1b5ce12b7),platform=Linux 3.10.0-693.21.1.el7.x86_64 x86_64)

Finally I applied the fix:
It works (badly) because I can run through more than 27 images, but the script likes everything (no upper/lower limits for followers have been applied) and every picture has the record:
Number of Followers: undefined
So ok, the script runs but only because it bypasses the value of number of followers which caused the errors above. Anyone in this situation as well?
Thank you.

@riccardorighettiphoto
I DO NOT KNOW how it output undefined value in all attempts, but wait, this problematic line should be solved definitely. _Let's change to another method!_

Solution: for the num_followers variable in like_util.py (_it is located currently in line 497 at main repo_) modify like this
replace (_the line below is taken from official file at main repo_)

num_followers = browser.execute_script(
    "return window._sharedData.entry_data."
    "ProfilePage[0].graphql.user.edge_followed_by.count")

with

num_followers = format_number(browser.find_element_by_xpath(
    "//li[2]/a/span[contains(@class, '_fd86t')]").text)

Note: For those using the old method in upper of the page and has not yet any problems, it is still recommended to use this new one, problem-free method!

The problem with followed_by variable in print_log_writer.py also gets the same fix

Solution: _open_ up print_log_writer.py and modify like this:
1. import format_numer near other imports at top of the file

from .util import format_number

2. replace

followed_by = browser.execute_script(
    "return window._sharedData.""entry_data.ProfilePage[0]."
    "graphql.user.edge_followed_by.count")

with

followed_by = format_number(browser.find_element_by_xpath(
    "//li[2]/a/span[contains(@class, '_fd86t')]").text)

@uluQulu just edited the code with your quick fix but it seems there's an error...
"method":"xpath","selector": li[2]/a/span[contains(@class, '_fd86t' Invalid Page: Message: no such element: Unable to locate element: {"method":"xpath","selector":"//li[2]/a/span[contains(@class, '_fd86t')]"}

Any idea what could have gone wrong?

@MrBeardedGuy
For some reasons, selenium makes trouble finding that element, knowing what version is your selenium and which webdriver you do use might help, but I tested and it works perfectly in Windows

Same issue here.

  (Session info: chrome=65.0.3325.181)
  (Driver info: chromedriver=2.37.544315 (730aa6a5fdba159ac9f4c1e8cbc59bf1b5ce12b7),platform=Linux 3.10.0-693.21.1.el7.x86_64 x86_64)

to those who have the #1785 issue, please do make sure you have the latest version of Chromedriver. if not make sure go download the latest version.

Still happening randomly with

Selenium 2.53.6
chromedriver=2.37

@MrBeardedGuy,
I don't know, maybe your system supports max that version, but would you try to upgrade selenium to the latest version?

for me, in Windows, I do pip install -U selenium regularly and currently it's 3.11

>pip show selenium
Name: selenium
Version: 3.11.0
Summary: Python bindings for Selenium
Home-page: https://github.com/SeleniumHQ/selenium/

see if it makes a change, _now_

Have been testing for a couple of days and it seems a stable fix! I believe it was an old version of selenium that was causing problems

@uluQulu Senior. Looks like the old nemesis is back again... is either of these fixes in the main repo? Or they still need to be manually applied?

(talking about the crash - when chrome shows - Sorry, something went wrong page)

Or rather - main repo files changed so much it is not clear now how to apply the new fix (lines u suggest replacing are not there anymore :D)

Hey @ArdySan2012
This is a huge thread and contains various fixes, ideas. And I don't remember I did PR any of them personally.
That's why I can't be sure how well but some of those pieces were committed by some guys in several PRs.

But it is fact that the method of handling _entry_data errors_ was born in this thread with the help of amazing people's amazing feedback, especially @Tachenz.

If you are having similar issues, it is best to provide a _troubleshoot information_ to get it fixed.

Regards.

@uluQulu thank you! Trying to catch that error now to troubleshoot it :) had to run it in cmd - as now I wake up and both chrome and script windows are just gone.

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

If this problem still occurs, please open a new issue

Was this page helpful?
0 / 5 - 0 ratings

Related issues

thisishotdog picture thisishotdog  ·  3Comments

ingorichter picture ingorichter  ·  3Comments

ghost picture ghost  ·  3Comments

converge picture converge  ·  3Comments

deronsizemore picture deronsizemore  ·  3Comments