Repository: InstaPy/InstaPy

Issue:
Save login info causes: Unable to login to Instagram! You will find more information in the logs above.
Hi,

i was trying to setup Instapy on DigitalOcean in headless mode but it always stopped with the info `Unable to login to Instagram! You will find more information in the logs above.`.
Ive tried a couple of solutions you can find in the Issues section of this repo but nothing worked out for me.
So I debugged Instapy locally with `headless_browser=False` and it turned out it always stopped at the "Save login" window. I think this window is not configured in the selenium workflow?

<img width="240" alt="Screenshot 2019-09-08 at 13 47 10" src="https://user-images.githubusercontent.com/1873375/64487844-f2376500-d23f-11e9-970c-ea46b6cd95b2.png">

Has anyone noticed the same problem? 

Edit: After clicking "Not now" manually it worked fine.


Discussion:
I have the same error launching the bot through my RaspBi3+
```
InstaPy Version: 0.6.3
 ._.  ._.  ._.  ._.  ._.  ._.  ._.
Workspace in use: "/root/InstaPy"
OOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO
INFO [2019-09-08 18:13:45] [xxx]  Session started!
oooooooooooooooooooooooooooooooooooooooooooooooooooooo
INFO [2019-09-08 18:13:45] [xxx]  -- Connection Checklist [1/3] (Internet Connection Status)
INFO [2019-09-08 18:13:46] [xxx]  - Internet Connection Status: ok
INFO [2019-09-08 18:13:46] [xxx]  - Current IP is "x.x.x.x" and it's from "xxx"
INFO [2019-09-08 18:13:46] [xxx]  -- Connection Checklist [2/3] (Instagram Server Status)
INFO [2019-09-08 18:13:59] [xxx]  - Instagram WebSite Status: Currently Up
INFO [2019-09-08 18:13:59] [xxx]  - Instagram Response Time: 34.407 ms
INFO [2019-09-08 18:13:59] [xxx]  - Instagram Reponse Code: 200
INFO [2019-09-08 18:13:59] [xxx]  - Instagram Server Status: ok
INFO [2019-09-08 18:13:59] [xxx]  -- Connection Checklist [3/3] (Hide Selenium Extension)
INFO [2019-09-08 18:13:59] [xxx]  - window.navigator.webdriver response: False
INFO [2019-09-08 18:13:59] [xxx]  - Hide Selenium Extension: ok
Cookie file not found, creating cookie...
.........................................................................................................................
CRITICAL [2019-09-08 18:14:40] [xxx]  Unable to login to Instagram! You will find more information in the logs above.
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

INFO [2019-09-08 18:14:42] [xxx]  Sessional Live Report:
        |> No any statistics to show


[Session lasted 1.12 minutes]
OOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO
INFO [2019-09-08 18:14:42] [xxx]  Session ended!
oooooooooooooooooooooooooooooooooooooooooooooooooooooooo



[Errno 2] No such file or directory: '/tmp/tmp8av5xdxy'

INFO [2019-09-08 18:14:42] [xxx]  Sessional Live Report:
        |> No any statistics to show


[Session lasted 1.12 minutes]
OOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO
INFO [2019-09-08 18:14:42] [xxx]  Session ended!
oooooooooooooooooooooooooooooooooooooooooooooooooooooooo
```

same problem as you, @Jostino :/
Same Problem Here
I had the same error, I solved the problem with 2 lines of code, here:

```
if "instagram.com/accounts/onetap" in browser.current_url:
        browser.get("https://instagram.com")
```

Under line 446, add it as you see in the photo. (login_util.py)
https://i.ibb.co/b2LgbJX/python.png

Simple as that :)
> I had the same error, I solved the problem with 2 lines of code, here:
> 
> ```
> if "instagram.com/accounts/onetap" in browser.current_url:
>         browser.get("https://instagram.com")
> ```
> 
> Under line 446, add it as you see in the photo. (login_util.py)
> https://i.ibb.co/b2LgbJX/python.png
> 
> Simple as that :)

I have check it but it doesn't work. Which IntsaPy version do you use?
> > I had the same error, I solved the problem with 2 lines of code, here:
> > ```
> > if "instagram.com/accounts/onetap" in browser.current_url:
> >         browser.get("https://instagram.com")
> > ```
> > 
> > 
> > Under line 446, add it as you see in the photo. (login_util.py)
> > https://i.ibb.co/b2LgbJX/python.png
> > Simple as that :)
> 
> I have check it but it doesn't work. Which IntsaPy version do you use?

Would you send me a screenshot from where you wrote the code?
Actually I have this situation:

```
find / -type f -name "login_util.py"
/root/.local/lib/python3.7/site-packages/instapy/login_util.py
/root/.local/lib/python3.5/site-packages/instapy/login_util.py
/usr/local/lib/python2.7/dist-packages/instapy/login_util.py
/usr/local/lib/python3.5/dist-packages/instapy/login_util.py
```
I've added the lines you mentioned in all these files, just to be sure.

It works!!

But now I have a different issue...
> Actually I have this situation:
> 
> ```
> find / -type f -name "login_util.py"
> /root/.local/lib/python3.7/site-packages/instapy/login_util.py
> /root/.local/lib/python3.5/site-packages/instapy/login_util.py
> /usr/local/lib/python2.7/dist-packages/instapy/login_util.py
> /usr/local/lib/python3.5/dist-packages/instapy/login_util.py
> ```
> 
> I've added the lines you mentioned in all these files, just to be sure.
> 
> It works!!
> 
> But now I have a different issue...

Please give me more details..
I had the same problem and the code you suggested seems to have **fixed it**.

But I don't know why now my script runs so slow. It's been stuck here for about 10 minutes:
```
Logged in successfully!
Saving account progress...
WARNING [2019-09-09 13:41:54] [XXX]  Unable to save account progress, skipping data update Message: TypeError: window._sharedData is undefined
```

Edit: After a few minutes the bot started interacting but as I said, is very very slow. My all Raspberry is sluggish while I run the script (which I haven't changed at all since the last update). And I seem to get this error too much frequently: `cannot get the post profile pic url`

After a reboot and a second attempt, this is what I get:
```
INFO [2019-09-09 13:59:10] [XXX]  Getting XXX image list...
Traceback (most recent call last):
  File "/home/pi/InstaPy/z_instabot.py", line 328, in interact_by
    randomize=True)
  File "/home/pi/.local/lib/python3.7/site-packages/instapy/instapy.py", line 5540, in interact_by_comments
    self.user_interact_media,
  File "/home/pi/.local/lib/python3.7/site-packages/instapy/instapy.py", line 2471, in interact_by_users
    media,
  File "/home/pi/.local/lib/python3.7/site-packages/instapy/like_util.py", line 450, in get_links_for_username
    browser, "profile", username, person, None, logger, logfolder
  File "/home/pi/.local/lib/python3.7/site-packages/instapy/unfollow_util.py", line 211, in get_following_status
    following_status = follow_button.text
  File "/home/pi/.local/lib/python3.7/site-packages/selenium/webdriver/remote/webelement.py", line 76, in text
    return self._execute(Command.GET_ELEMENT_TEXT)['value']
  File "/home/pi/.local/lib/python3.7/site-packages/selenium/webdriver/remote/webelement.py", line 633, in _execute
    return self._parent.execute(command, params)
  File "/home/pi/.local/lib/python3.7/site-packages/selenium/webdriver/remote/webdriver.py", line 321, in execute
    self.error_handler.check_response(response)
  File "/home/pi/.local/lib/python3.7/site-packages/selenium/webdriver/remote/errorhandler.py", line 242, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.StaleElementReferenceException: Message: The element reference of <button class="_5f5mN       jIbKX  _6VtSN     yZn4P   "> is stale; either the element is no longer attached to the DOM, it is not in the current frame context, or the document has been refreshed
```
> > > I had the same error, I solved the problem with 2 lines of code, here:
> > > ```
> > > if "instagram.com/accounts/onetap" in browser.current_url:
> > >         browser.get("https://instagram.com")
> > > ```
> > > 
> > > 
> > > Under line 446, add it as you see in the photo. (login_util.py)
> > > https://i.ibb.co/b2LgbJX/python.png
> > > Simple as that :)
> > 
> > 
> > I have check it but it doesn't work. Which IntsaPy version do you use?
> 
> Would you send me a screenshot from where you wrote the code?

Where's my fault? Thanks! 
https://ibb.co/Ldsy60R
> 
> 
> I had the same problem and the code you suggested seems to have **fixed it**.
> 
> But I don't know why now my script runs so slow. It's been stuck here for about 10 minutes:
> 
> ```
> Logged in successfully!
> Saving account progress...
> WARNING [2019-09-09 13:41:54] [XXX]  Unable to save account progress, skipping data update Message: TypeError: window._sharedData is undefined
> ```
> 
> Edit: After a few minutes the bot started interacting but as I said, is very very slow. My all Raspberry is sluggish while I run the script (which I haven't changed at all since the last update). And I seem to get this error too much frequently: `cannot get the post profile pic url`
> 
> After a reboot and a second attempt, this is what I get:
> 
> ```
> INFO [2019-09-09 13:59:10] [XXX]  Getting XXX image list...
> Traceback (most recent call last):
>   File "/home/pi/InstaPy/z_instabot.py", line 328, in interact_by
>     randomize=True)
>   File "/home/pi/.local/lib/python3.7/site-packages/instapy/instapy.py", line 5540, in interact_by_comments
>     self.user_interact_media,
>   File "/home/pi/.local/lib/python3.7/site-packages/instapy/instapy.py", line 2471, in interact_by_users
>     media,
>   File "/home/pi/.local/lib/python3.7/site-packages/instapy/like_util.py", line 450, in get_links_for_username
>     browser, "profile", username, person, None, logger, logfolder
>   File "/home/pi/.local/lib/python3.7/site-packages/instapy/unfollow_util.py", line 211, in get_following_status
>     following_status = follow_button.text
>   File "/home/pi/.local/lib/python3.7/site-packages/selenium/webdriver/remote/webelement.py", line 76, in text
>     return self._execute(Command.GET_ELEMENT_TEXT)['value']
>   File "/home/pi/.local/lib/python3.7/site-packages/selenium/webdriver/remote/webelement.py", line 633, in _execute
>     return self._parent.execute(command, params)
>   File "/home/pi/.local/lib/python3.7/site-packages/selenium/webdriver/remote/webdriver.py", line 321, in execute
>     self.error_handler.check_response(response)
>   File "/home/pi/.local/lib/python3.7/site-packages/selenium/webdriver/remote/errorhandler.py", line 242, in check_response
>     raise exception_class(message, screen, stacktrace)
> selenium.common.exceptions.StaleElementReferenceException: Message: The element reference of <button class="_5f5mN       jIbKX  _6VtSN     yZn4P   "> is stale; either the element is no longer attached to the DOM, it is not in the current frame context, or the document has been refreshed
> ```

Same problem
I've opened an issue here:
https://github.com/timgrossmann/InstaPy/issues/5038
Same problem on login and same problem having everything run slow and crash on my raspberry 3b+
Same problem on 0.6.3 as well
@gdgeyter and @kami4ka di you tried this suggestion?
https://github.com/timgrossmann/InstaPy/issues/5035#issuecomment-529238015

it worked for me about the "unable login...."


Resolving patch:
diff --git a/instapy/login_util.py b/instapy/login_util.py
--- a/instapy/login_util.py
+++ b/instapy/login_util.py
@@ -466,6 +466,9 @@ def login_user(
     except NoSuchElementException:
         pass
 
+    if "instagram.com/accounts/onetap" in browser.current_url:
+        browser.get("https://instagram.com")
+
     # wait until page fully load
     explicit_wait(browser, "PFL", [], logger, 5)
 


Test patch: