investopedia_simulator_api icon indicating copy to clipboard operation
investopedia_simulator_api copied to clipboard

Cannot login?

Open radqnico opened this issue 1 year ago • 3 comments

Reproduce: insert valid credentials into the dictionary and see this error:

TimeoutError: Waiting for selector `::-p-xpath(//span[contains(text(),"LOG IN")])` failed: Waiting failed: 3000ms exceeded
    at new WaitTask (file:///F:/Progetti/Python/SeleniumStock/node_modules/puppeteer-core/lib/esm/puppeteer/common/WaitTask.js:47:34)
    at IsolatedWorld.waitForFunction (file:///F:/Progetti/Python/SeleniumStock/node_modules/puppeteer-core/lib/esm/puppeteer/api/Realm.js:22:26)
    at PQueryHandler.waitFor (file:///F:/Progetti/Python/SeleniumStock/node_modules/puppeteer-core/lib/esm/puppeteer/common/QueryHandler.js:167:95)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async CdpFrame.waitForSelector (file:///F:/Progetti/Python/SeleniumStock/node_modules/puppeteer-core/lib/esm/puppeteer/api/Frame.js:466:21)
    at async CdpPage.waitForSelector (file:///F:/Progetti/Python/SeleniumStock/node_modules/puppeteer-core/lib/esm/puppeteer/api/Page.js:1287:20)
    at async file:///F:/Progetti/Python/SeleniumStock/auth.js:46:29
Traceback (most recent call last):
  File "F:\Progetti\Python\SeleniumStock\example.py", line 8, in <module>
    client = InvestopediaApi(credentials)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "F:\Progetti\Python\SeleniumStock\investopedia_api.py", line 10, in __init__
    Session.login(credentials)
  File "F:\Progetti\Python\SeleniumStock\session_singleton.py", line 97, in login
    raise InvestopediaAuthException("Unable to login with credentials '%s', '%s'" % (credentials['username'],credentials['password']))
session_singleton.InvestopediaAuthException: Unable to login with credentials '--------', '-------------'

radqnico avatar Mar 19 '24 18:03 radqnico

It looks like Puppeteer can't find the LOG IN link when loading the page. Are you running this from outside the United States? I'm wondering if it can't find it because the language changed on the page to something other than English.

Here's a potential workaround for now:

  1. Open a Chrome or Firefox window and open the Dev Tools (press F12) and click on the Network tab
  2. Navigate to https://www.investopedia.com/simulator/ and login
  3. In the filter box, type "token"
  4. Select the token request
  5. Click on the Response tab
  6. You should see a JSON object that looks something like this:
{
    "access_token": "eyJhbGciO...",
    "expires_in": 300,
    "refresh_expires_in": 604800,
    "refresh_token": "eyJhbGciOiJIUzI1NiIsInR5...",
    "token_type": "Bearer",
    "id_token": "eyJhbGciOiJS...",
    "not-before-policy": 1638915147,
    "session_state": "46eff9cf...",
    "scope": "openid profile email"
}
  1. Select everything in the response and copy it.
  2. In the base file directory create a new file called auth.json and paste the contents of the response in that file and save it.
  3. Try running again.

Let me know if that works or if you need clarification.

dchrostowski avatar Mar 19 '24 20:03 dchrostowski

This method got me banned temporarily by IP from the website 😂 but no login yet

radqnico avatar Mar 20 '24 17:03 radqnico

Runnying example.py, I've tried 2 different accounts and I get: TimeoutError: Waiting for selector ::-p-xpath(//input[@id="password"]) failed: Waiting failed: 3000ms exceeded at new WaitTask (file:///F:/spaces/TimeHaxor/investopedia_simulator_api/node_modules/puppeteer-core/lib/esm/puppeteer/common/WaitTask.js:47:34) at IsolatedWorld.waitForFunction (file:///F:/spaces/TimeHaxor/investopedia_simulator_api/node_modules/puppeteer-core/lib/esm/puppeteer/api/Realm.js:22:26) at PQueryHandler.waitFor (file:///F:/spaces/TimeHaxor/investopedia_simulator_api/node_modules/puppeteer-core/lib/esm/puppeteer/common/QueryHandler.js:167:95) at process.processTicksAndRejections (node:internal/process/task_queues:95:5) at async CdpFrame.waitForSelector (file:///F:/spaces/TimeHaxor/investopedia_simulator_api/node_modules/puppeteer-core/lib/esm/puppeteer/api/Frame.js:466:21) at async CdpPage.waitForSelector (file:///F:/spaces/TimeHaxor/investopedia_simulator_api/node_modules/puppeteer-core/lib/esm/puppeteer/api/Page.js:1287:20) at async file:///F:/spaces/TimeHaxor/investopedia_simulator_api/auth.js:67:32 Traceback (most recent call last): File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.12_3.12.1264.0_x64__qbz5n2kfra8p0\Lib\runpy.py", line 198, in _run_module_as_main return _run_code(code, main_globals, None, ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.12_3.12.1264.0_x64__qbz5n2kfra8p0\Lib\runpy.py", line 88, in run_code exec(code, run_globals) File "c:\Users\jrade.cursor\extensions\ms-python.debugpy-2024.8.0-win32-x64\bundled\libs\debugpy\adapter/../..\debugpy\launcher/../..\debugpy_main.py", line 39, in cli.main() File "c:\Users\jrade.cursor\extensions\ms-python.debugpy-2024.8.0-win32-x64\bundled\libs\debugpy\adapter/../..\debugpy\launcher/../..\debugpy/..\debugpy\server\cli.py", line 430, in main run() File "c:\Users\jrade.cursor\extensions\ms-python.debugpy-2024.8.0-win32-x64\bundled\libs\debugpy\adapter/../..\debugpy\launcher/../..\debugpy/..\debugpy\server\cli.py", line 284, in run_file runpy.run_path(target, run_name="main") File "c:\Users\jrade.cursor\extensions\ms-python.debugpy-2024.8.0-win32-x64\bundled\libs\debugpy_vendored\pydevd_pydevd_bundle\pydevd_runpy.py", line 321, in run_path return _run_module_code(code, init_globals, run_name, ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "c:\Users\jrade.cursor\extensions\ms-python.debugpy-2024.8.0-win32-x64\bundled\libs\debugpy_vendored\pydevd_pydevd_bundle\pydevd_runpy.py", line 135, in _run_module_code _run_code(code, mod_globals, init_globals, File "c:\Users\jrade.cursor\extensions\ms-python.debugpy-2024.8.0-win32-x64\bundled\libs\debugpy_vendored\pydevd_pydevd_bundle\pydevd_runpy.py", line 124, in _run_code exec(code, run_globals) File "F:\spaces\TimeHaxor\investopedia_simulator_api\example.py", line 15, in client = InvestopediaApi(credentials) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "F:\spaces\TimeHaxor\investopedia_simulator_api\investopedia_api.py", line 10, in init Session.login(credentials) File "F:\spaces\TimeHaxor\investopedia_simulator_api\session_singleton.py", line 97, in login raise InvestopediaAuthException("Unable to login with credentials '%s', '%s'" % (credentials['username'],credentials['password']))
session_singleton.InvestopediaAuthException: Unable to login with credentials '...', '...'

I tried the F12 token lookup but I get "No matching selector or style".

I've also narrowed this down to a missing auth.json issue. Creating one, I got a access_token key error. Adding that key, it came up with a refresh_token key error.

session_singleton.py:47: UserWarning: Problem with auth tokens, attempting to login again... warnings.warn("Problem with auth tokens, attempting to login again...")

TimeHaxor avatar Jul 24 '24 03:07 TimeHaxor