Instapy: Cannot login: Stuck on Accept Cookies page

Created on 21 Oct 2020  路  3Comments  路  Source: timgrossmann/InstaPy


Expected Behavior

Login and start working

Current Behavior

INFO [2020-10-21 01:15:56] [my.account] Session started!
oooooooooooooooooooooooooooooooooooooooooooooooooooooo
INFO [2020-10-21 01:15:56] [my.account] -- Connection Checklist [1/2] (Internet Connection Status)
INFO [2020-10-21 01:15:57] [my.account] - Internet Connection Status: ok
INFO [2020-10-21 01:15:57] [my.account] - Current IP is "xx.yyy.zz.aa" and it's from "Germany/DE"
INFO [2020-10-21 01:15:57] [my.account] -- Connection Checklist [2/2] (Hide Selenium Extension)
INFO [2020-10-21 01:15:57] [my.account] - window.navigator.webdriver response: None
INFO [2020-10-21 01:15:57] [my.account] - Hide Selenium Extension: ok
Cookie file not found, creating cookie...
INFO [2020-10-21 01:16:42] [my.account] Timed out with failure while explicitly waiting until visibility of element located!


If raising an issue, please also upload the file located at:
/tmp/20201021-011647.html

Temp File is about accepting cookies! It appears the script is stuck on this page.

Continue to Instagram by accepting cookies?

One of the ways we use cookies is to show you useful and relevant ads on and off Instagram. You can read more about the ways we use cookies in our Cookie Policy. You can control how we use data to show you ads by using the tools described below.

Follow the instructions provided by your website or mobile browser (usually located within the "Help", "Tools" or "Edit" facility) to modify your cookie settings. Please note that if you set your browser to disable cookies or other technologies, you may not be able to access certain parts of our Service and other parts of our Service may not work properly.

To learn more about the choices that advertisers provide generally for individuals to influence how information about their online activities over time and across third-party Web sites or online services is collected and used, visit the Network Advertising Initiative, the Digital Advertising Alliance, or the European Digital Advertising Alliance.

In addition, your browser or device may offer settings that allow you to choose whether browser cookies are set and to delete them. These controls vary by browser, and manufacturers may change both the settings they make available and how they work at any time. As of 5 October 2020, you may find additional information about the controls offered by popular browsers at the links below. Certain parts of the Facebook Products may not work properly if you have disabled browser cookie use. Please be aware these controls are distinct from the controls that Facebook offers you.

Possible Solution (optional)

Code something to ship the accept cookie page?

InstaPy configuration

standard quickstart script

in progress

Most helpful comment

This Code from https://github.com/tlaskyd helped

`    # Accept cookies quick and dirty fix.
    insta.browser.get('https://instagram.com/accounts/login')
    insta.browser.implicitly_wait(5)
    for element in insta.browser.find_elements_by_tag_name('button'):
        if element.text.strip().lower() == 'accept':
            element.click()
            break`

Insert it into util.py

@contextmanager
def smart_run(session, threaded=False):
    try:
# Accept cookies quick and dirty fix.
        session.browser.get('https://instagram.com/accounts/login')
        session.browser.implicitly_wait(5)
        for element in session.browser.find_elements_by_tag_name('button'):
         if element.text.strip().lower() == 'accept': 
            element.click()
            break

        session.login()
        yield
    except NoSuchElementException:
        # The problem is with a change in IG page layout
        log_file = "{}.html".format(time.strftime("%Y%m%d-%H%M%S"))
        file_path = os.path.join(gettempdir(), log_file)

        with open(file_path, "wb") as fp:
            fp.write(session.browser.page_source.encode("utf-8"))

        print(
            "{0}\nIf raising an issue, "
            "please also upload the file located at:\n{1}\n{0}".format(
                "*" * 70, file_path
            )
        )
    except KeyboardInterrupt:
        clean_exit("You have exited successfully.")
    finally:
        session.end(threaded_session=threaded)

All 3 comments

This Code from https://github.com/tlaskyd helped

`    # Accept cookies quick and dirty fix.
    insta.browser.get('https://instagram.com/accounts/login')
    insta.browser.implicitly_wait(5)
    for element in insta.browser.find_elements_by_tag_name('button'):
        if element.text.strip().lower() == 'accept':
            element.click()
            break`

Insert it into util.py

@contextmanager
def smart_run(session, threaded=False):
    try:
# Accept cookies quick and dirty fix.
        session.browser.get('https://instagram.com/accounts/login')
        session.browser.implicitly_wait(5)
        for element in session.browser.find_elements_by_tag_name('button'):
         if element.text.strip().lower() == 'accept': 
            element.click()
            break

        session.login()
        yield
    except NoSuchElementException:
        # The problem is with a change in IG page layout
        log_file = "{}.html".format(time.strftime("%Y%m%d-%H%M%S"))
        file_path = os.path.join(gettempdir(), log_file)

        with open(file_path, "wb") as fp:
            fp.write(session.browser.page_source.encode("utf-8"))

        print(
            "{0}\nIf raising an issue, "
            "please also upload the file located at:\n{1}\n{0}".format(
                "*" * 70, file_path
            )
        )
    except KeyboardInterrupt:
        clean_exit("You have exited successfully.")
    finally:
        session.end(threaded_session=threaded)

session.browser.get('https://instagram.com/accounts/login')
session.browser.implicitly_wait(5)
for element in session.browser.find_elements_by_tag_name('button'):
if element.text.strip().lower() == 'accept':
element.click()
break

I modified util.py and get error:
Traceback (most recent call last): File "quickstart.py", line 2, in <module> from instapy import InstaPy File "/home/pi/new-bot/InstaPy/instapy/__init__.py", line 6, in <module> from .instapy import InstaPy File "/home/pi/new-bot/InstaPy/instapy/instapy.py", line 34, in <module> from .comment_util import comment_image File "/home/pi/new-bot/InstaPy/instapy/comment_util.py", line 8, in <module> from .util import update_activity File "/home/pi/new-bot/InstaPy/instapy/util.py", line 1922 session.browser.get('https://instagram.com/accounts/login') IndentationError: expected an indented block

@OnlyOneMoreHour Maybe you should open a merge request to elaborate a sufficient solution on master

Was this page helpful?
0 / 5 - 0 ratings

Related issues

seuraltimez picture seuraltimez  路  3Comments

harrypython picture harrypython  路  3Comments

tibor picture tibor  路  3Comments

v77v picture v77v  路  3Comments

ingorichter picture ingorichter  路  3Comments