investopedia_simulator_api
investopedia_simulator_api copied to clipboard
Cannot login?
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 '--------', '-------------'
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:
- Open a Chrome or Firefox window and open the Dev Tools (press F12) and click on the Network tab
- Navigate to https://www.investopedia.com/simulator/ and login
- In the filter box, type "token"
- Select the token request
- Click on the Response tab
- 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"
}
- Select everything in the response and copy it.
- In the base file directory create a new file called
auth.jsonand paste the contents of the response in that file and save it. - Try running again.
Let me know if that works or if you need clarification.
This method got me banned temporarily by IP from the website 😂 but no login yet
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
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...")