Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Accepting cookie #5815

Closed
itssmaxy opened this issue Oct 7, 2020 · 24 comments
Closed

Accepting cookie #5815

itssmaxy opened this issue Oct 7, 2020 · 24 comments

Comments

@itssmaxy
Copy link

itssmaxy commented Oct 7, 2020

There's this annoying popup that shows up now when connecting to instagram. Does anyone know where in login.py I should code the new browser.click() for accepting cookies?

@Polkyanik
Copy link

Polkyanik commented Oct 8, 2020

@itssmaxy
i have the same problem even after updating the files .. here we talked about the problem

Timed out with failure while explicitly waiting until title contains 'Login' string! #5799

Subject: instagram_title_fix #5813

@Booleboole
Copy link

Try to apply the fix and remove log folder but nothing change...

@jhrtrl
Copy link

jhrtrl commented Oct 9, 2020

Yes I have the same issue when I remove the cookies. When I delete the cookies, I need to accept the cookies policies from instagram again. So the solution is not remove the cookies but if you did, need to accept the cookies policies again.

Some fix for this? I already have changed the title for Instagram. This is not the problem anymore, for me at least.

@Polkyanik
Copy link

Polkyanik commented Oct 9, 2020

@elulcao

Try to apply the fix and remove log folder but nothing change...
 
1602270018149	webdriver::server	DEBUG	<- 200 OK {"value":null}
1602270018152	webdriver::server	DEBUG	-> POST /session/2eeca74b-a3e4-4aae-8934-952921211dac/execute/sync {"script": "return window._sharedData.config.viewer", "args": []}
1602270018157	Marionette	DEBUG	0 -> [0,29,"WebDriver:ExecuteScript",{"args":[],"newSandbox":false,"script":"return window._sharedData.config.viewer","specialPowers":false}]
1602270018172	Marionette	DEBUG	0 <- [1,29,{"error":"javascript error","message":"TypeError: window._sharedData is undefined","stacktrace":"@https://www.instagram.com/:2:7\n@https://www.instagram.com/:3:8\n"},null]
1602270018173	webdriver::server	DEBUG	<- 500 Internal Server Error {"value":{"error":"javascript error","message":"TypeError: window._sharedData is undefined","stacktrace":"@https://www.instagram.com/:2:7\n@https://www.instagram.com/:3:8\n"}}
1602270018175	webdriver::server	DEBUG	-> POST /session/2eeca74b-a3e4-4aae-8934-952921211dac/element {"using": "xpath", "value": "//button[text()='Log In']"}
1602270018181	Marionette	DEBUG	0 -> [0,30,"WebDriver:FindElement",{"using":"xpath","value":"//button[text()='Log In']"}]
1602270024104	Marionette	DEBUG	0 <- [1,30,{"error":"no such element","message":"Unable to locate element: //button[text()='Log In']","stacktrace":"WebDriverError ... entError@chrome://marionette/content/error.js:387:5\nelement.find/</<@chrome://marionette/content/element.js:343:16\n"},null]
1602270024106	webdriver::server	DEBUG	<- 404 Not Found {"value":{"error":"no such element","message":"Unable to locate element: //button[text()='Log In']","stacktrace":"WebDriverError@chrome://marionette/content/error.js:175:5\nNoSuchElementError@chrome://marionette/content/error.js:387:5\nelement.find/</<@chrome://marionette/content/element.js:343:16\n"}}
1602270024109	webdriver::server	DEBUG	-> POST /session/2eeca74b-a3e4-4aae-8934-952921211dac/element {"using": "xpath", "value": "//a[text()='Log in']"}
1602270024111	Marionette	DEBUG	0 -> [0,31,"WebDriver:FindElement",{"using":"xpath","value":"//a[text()='Log in']"}]
1602270029211	Marionette	DEBUG	0 <- [1,31,{"error":"no such element","message":"Unable to locate element: //a[text()='Log in']","stacktrace":"WebDriverError@chro ... entError@chrome://marionette/content/error.js:387:5\nelement.find/</<@chrome://marionette/content/element.js:343:16\n"},null]
1602270029213	webdriver::server	DEBUG	<- 404 Not Found {"value":{"error":"no such element","message":"Unable to locate element: //a[text()='Log in']","stacktrace":"WebDriverError@chrome://marionette/content/error.js:175:5\nNoSuchElementError@chrome://marionette/content/error.js:387:5\nelement.find/</<@chrome://marionette/content/element.js:343:16\n"}}
1602270029216	webdriver::server	DEBUG	-> POST /session/2eeca74b-a3e4-4aae-8934-952921211dac/element {"using": "xpath", "value": "//div[text()='Log In']"}
1602270029219	Marionette	DEBUG	0 -> [0,32,"WebDriver:FindElement",{"using":"xpath","value":"//div[text()='Log In']"}]
1602270034236	Marionette	DEBUG	0 <- [1,32,{"error":"no such element","message":"Unable to locate element: //div[text()='Log In']","stacktrace":"WebDriverError@ch ... entError@chrome://marionette/content/error.js:387:5\nelement.find/</<@chrome://marionette/content/element.js:343:16\n"},null]
1602270034238	webdriver::server	DEBUG	<- 404 Not Found {"value":{"error":"no such element","message":"Unable to locate element: //div[text()='Log In']","stacktrace":"WebDriverError@chrome://marionette/content/error.js:175:5\nNoSuchElementError@chrome://marionette/content/error.js:387:5\nelement.find/</<@chrome://marionette/content/element.js:343:16\n"}}
1602270034243	webdriver::server	DEBUG	-> DELETE /session/2eeca74b-a3e4-4aae-8934-952921211dac/cookie 
1602270034246	Marionette	DEBUG	0 -> [0,33,"WebDriver:DeleteAllCookies",{}]
1602270034265	Marionette	DEBUG	0 <- [1,33,null,{"value":null}]
1602270034267	webdriver::server	DEBUG	<- 200 OK {"value":null}
1602270034271	webdriver::server	DEBUG	-> DELETE /session/2eeca74b-a3e4-4aae-8934-952921211dac 
1602270034274	Marionette	DEBUG	0 -> [0,34,"Marionette:Quit",{"flags":["eForceQuit"]}]
1602270034278	Marionette	INFO	Stopped listening on port 44323
1602270034569	Marionette	TRACE	Received observer notification quit-application
1602270034579	Marionette	DEBUG	0 <- [1,34,null,{"cause":"shutdown"}]
1602270034673	webdriver::server	DEBUG	Deleting session
1602270034704	Marionette	DEBUG	0 -> [0,35,"Marionette:Quit",{"flags":["eForceQuit"]}]
1602270034706	Marionette	DEBUG	0 <- [1,35,{"error":"invalid session id","message":"Tried to run command without establishing a connection","stacktrace":"WebDrive ... t@chrome://marionette/content/server.js:249:9\n_onJSONObjectReady/<@chrome://marionette/content/transport.js:503:20\n"},null]
1602270034725	Marionette	DEBUG	Closed connection 0
1602270036245	Marionette	TRACE	Received observer notification xpcom-will-shutdown
1602270036245	Marionette	DEBUG	Resetting recommended pref apz.content_response_timeout
1602270036246	Marionette	DEBUG	Resetting recommended pref browser.contentblocking.introCount
1602270036246	Marionette	DEBUG	Resetting recommended pref browser.download.panel.shown
1602270036246	Marionette	DEBUG	Resetting recommended pref browser.pagethumbnails.capturing_disabled
1602270036246	Marionette	DEBUG	Resetting recommended pref browser.tabs.disableBackgroundZombification
1602270036247	Marionette	DEBUG	Resetting recommended pref browser.tabs.remote.separatePrivilegedContentProcess
1602270036247	Marionette	DEBUG	Resetting recommended pref browser.tabs.unloadOnLowMemory
1602270036247	Marionette	DEBUG	Resetting recommended pref browser.tabs.warnOnCloseOtherTabs
1602270036247	Marionette	DEBUG	Resetting recommended pref browser.urlbar.suggest.searches
1602270036248	Marionette	DEBUG	Resetting recommended pref datareporting.policy.dataSubmissionPolicyAccepted
1602270036248	Marionette	DEBUG	Resetting recommended pref dom.disable_beforeunload
1602270036248	Marionette	DEBUG	Resetting recommended pref dom.file.createInChild
1602270036248	Marionette	DEBUG	Resetting recommended pref extensions.getAddons.cache.enabled
1602270036248	Marionette	DEBUG	Resetting recommended pref extensions.webservice.discoverURL
1602270036249	Marionette	DEBUG	Resetting recommended pref network.http.prompt-temp-redirect
1602270036249	Marionette	DEBUG	Resetting recommended pref network.http.speculative-parallel-limit
1602270036249	Marionette	DEBUG	Resetting recommended pref security.certerrors.mitm.priming.enabled
1602270036249	Marionette	DEBUG	Resetting recommended pref security.notification_enable_delay
1602270036249	Marionette	DEBUG	Resetting recommended pref signon.autofillForms
1602270036250	Marionette	DEBUG	Resetting recommended pref toolkit.cosmeticAnimations.enabled
1602270036251	Marionette	DEBUG	Remote service is inactive
1602270037113	geckodriver::marionette	DEBUG	Browser process stopped: exit code: 0
1602270037156	webdriver::server	DEBUG	<- 200 OK {"value":null}

@elulcao
Copy link
Collaborator

elulcao commented Oct 10, 2020

1602270034271 webdriver::server DEBUG -> DELETE /session/2eeca74b-a3e4-4aae-8934-952921211dac
1602270034274 Marionette DEBUG 0 -> [0,34,"Marionette:Quit",{"flags":["eForceQuit"]}]
1602270034278 Marionette INFO Stopped listening on port 44323
1602270034569 Marionette TRACE Received observer notification quit-application
1602270034579 Marionette DEBUG 0 <- [1,34,null,{"cause":"shutdown"}]
1602270034673 webdriver::server DEBUG Deleting session
1602270034704 Marionette DEBUG 0 -> [0,35,"Marionette:Quit",{"flags":["eForceQuit"]}]
1602270034706 Marionette DEBUG 0 <- [1,35,{"error":"invalid session id","message":"Tried to run command without establishing a connection","stacktrace":"WebDrive ... t@chrome://marionette/content/server.js:249:9\n_onJSONObjectReady/<@chrome://marionette/content/transport.js:503:20\n"},null]
1602270034725 Marionette DEBUG Closed connection 0

HI @Polkyanik
Reviewed the trace provided but still looking for what could be the culprit of this issue, this time is not the same for the Web Title but the A/B test. The path that is used is login_elem_no_such_exception_2 and condition is raised when cookie exist but cannot be used for any reason.

@Polkyanik
Copy link

@elulcao
understood, I trust in you! you are super! (Y)

tnx

@mesoller
Copy link

Yes I have the same issue when I remove the cookies. When I delete the cookies, I need to accept the cookies policies from instagram again. So the solution is not remove the cookies but if you did, need to accept the cookies policies again.

Some fix for this? I already have changed the title for Instagram. This is not the problem anymore, for me at least.

How exactly to change "Login" text to "Instagram"? Which .py script and which line?

@luismiparra
Copy link

Having the same issue here.

@StivGiobs
Copy link

Is the problem already solved?

@Booleboole
Copy link

I resolve only connect to my raspberry via vnc, start the script and manually click on "accept coockies"...
Only the First time, now the script work normally
If You cancel the cookie file the problem return

@StivGiobs
Copy link

I resolve only connect to my raspberry via vnc, start the script and manually click on "accept coockies"...
Only the First time, now the script work normally
If You cancel the cookie file the problem return

I’m on Mac OS. Is possible manually add cookie files into instapy folder?

If yes, how can I find the correct folder?

@Booleboole
Copy link

I resolve only connect to my raspberry via vnc, start the script and manually click on "accept coockies"...
Only the First time, now the script work normally
If You cancel the cookie file the problem return

I’m on Mac OS. Is possible manually add cookie files into instapy folder?

If yes, how can I find the correct folder?

Sorry, is impossibile to create and put in folder the cookie file.
Firefox use an internal System to storage the cookie ( all the cookies in one file)
When you run the script (not in headless mode) in a PC or in your Mac, and when you see the message click on "agree cookies", will be create a new file.
The file is stored in InstaPy folder
INSTAPY/LOG/"YOUR USER" / "YOUR USER" _COOCKIE.PKL

@itssmaxy
Copy link
Author

Basically guys, if you are using the browser and running the script on your computer, headless. Then you just need to update the xpath by adding the "Accept Cookie" button. Then in login.py make sure it accepts cookie first and then updates browser activity. Its not that difficult and since I ALWAYS have to accept cookie for some reason, this solution seems to work

@ismaeljmf
Copy link

Hi All,
.
I have solved this issue doing some steps:

  1. Delete all logs about your workspace
  2. Cleanup all history of Firefox
  3. Run script and click on accept cookies and login manually.
  4. Stop script
  5. Run again script.

@tlaskyd
Copy link

tlaskyd commented Oct 19, 2020

This is my quick and dirty fix. Place it before .login() call.

    # 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

@StivGiobs
Copy link

This is my quick and dirty fix. Place it before .login() call.

    # 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

Which file I have to correct?

@OnlyOneMoreHour
Copy link

This is my quick and dirty fix. Place it before .login() call.

    # 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

Thanks. This helped me with my cookie issue I reported here:
https://github.com/timgrossmann/InstaPy/issues/5837

@OnlyOneMoreHour
Copy link

This is my quick and dirty fix. Place it before .login() call.

    # 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

Which file I have to correct?


> 
> 
> > This is my quick and dirty fix. Place it before .login() call.
> > ```
> >     # 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
> > ```
> 
> Which file I have to correct?

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)

@CryptoCodeing
Copy link

CryptoCodeing commented Nov 8, 2020

This is my quick and dirty fix. Place it before .login() call.

    # 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

Where do i find the login.py file to add youre code?
I cannot fin dit in InstaPy folder Nor in my Solution folder

Thanks for your help!

EDIT: Found path it is as following: C:\Users[WindowsUser]\AppData\Local\Programs\Python\Python36-32\Lib\site-packages\instapy

@CryptoCodeing
Copy link

This is my quick and dirty fix. Place it before .login() call.

    # 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

Which file I have to correct?


> 
> 
> > This is my quick and dirty fix. Place it before .login() call.
> > ```
> >     # 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
> > ```
> 
> Which file I have to correct?

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)

C:\Users[WindowsUser]\AppData\Local\Programs\Python\Python36-32\Lib\site-packages\instapy

@Abassina
Copy link

Guys just the following code into the login_util.py file! If you could not find the file, than just use the debugger of your IDE and go step by step through you quickfile.py

........
def login_user(
browser,
username,
password,
logger,
logfolder,
proxy_address,
security_code_to_phone,
security_codes,
want_check_browser,
):
"""Logins the user with the given username and password"""
assert username, "Username not provided"
assert password, "Password not provided"

# Hotfix - this check crashes more often than not -- plus in not necessary,
# I can verify my own connection
if want_check_browser:
    if not check_browser(browser, logfolder, logger, proxy_address):
        return False

ig_homepage = "https://www.instagram.com"
web_address_navigator(browser, ig_homepage)

Here comes the important code to put in !!!!!

for element in browser.find_elements_by_tag_name('button'):
    if element.text.strip().lower() == 'accept':
        element.click()
        break

here the important code ends!!!!!!

cookie_file = "{0}{1}_cookie.pkl".format(logfolder, username)
cookie_loaded = None
login_state = None

# try to load cookie from username
try:
    for cookie in pickle.load(open(cookie_file, "rb")):
        # SameSite = Strict, your cookie will only be sent in a
        # first-party context. In user terms, the cookie will only be sent
        # if the site for the cookie matches the site currently shown in
        # the browser's URL bar.
        if "sameSite" in cookie and cookie["sameSite"] == "None":
            cookie["sameSite"] = "Strict"

        browser.add_cookie(cookie)

@boina-n
Copy link

boina-n commented Mar 8, 2021

Guys just the following code into the login_util.py file! If you could not find the file, than just use the debugger of your IDE and go step by step through you quickfile.py

........
def login_user(
browser,
username,
password,
logger,
logfolder,
proxy_address,
security_code_to_phone,
security_codes,
want_check_browser,
):
"""Logins the user with the given username and password"""
assert username, "Username not provided"
assert password, "Password not provided"

# Hotfix - this check crashes more often than not -- plus in not necessary,
# I can verify my own connection
if want_check_browser:
    if not check_browser(browser, logfolder, logger, proxy_address):
        return False

ig_homepage = "https://www.instagram.com"
web_address_navigator(browser, ig_homepage)

Here comes the important code to put in !!!!!

for element in browser.find_elements_by_tag_name('button'):
    if element.text.strip().lower() == 'accept':
        element.click()
        break

here the important code ends!!!!!!

cookie_file = "{0}{1}_cookie.pkl".format(logfolder, username)
cookie_loaded = None
login_state = None

# try to load cookie from username
try:
    for cookie in pickle.load(open(cookie_file, "rb")):
        # SameSite = Strict, your cookie will only be sent in a
        # first-party context. In user terms, the cookie will only be sent
        # if the site for the cookie matches the site currently shown in
        # the browser's URL bar.
        if "sameSite" in cookie and cookie["sameSite"] == "None":
            cookie["sameSite"] = "Strict"

        browser.add_cookie(cookie)

Hello @Abassina,

Was this fix merged in the repo so we can get benefice from it just by pulling the module instead of hacking the code which might be overridden in case of a new release or reinstall?

I did a clean install and seems like this problem is still there.

Thanks yall for your contribution :)

@elulcao
Copy link
Collaborator

elulcao commented Mar 9, 2021

@boina-n
Is this issue with the second popup window for the IG cookie reproducible after the latest commit?

@boina-n
Copy link

boina-n commented Mar 9, 2021

@elulcao

I believe yes, as I did this command to upgrade the module: pip install git+https://github.com/timgrossmann/InstaPy.git --upgrade

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests