error when creating API object
Closed this issue · 9 comments
Describe the bug
When I run code to get the API I get runtime error :
/simpliGetFirstToken.py", line 34, in main api = await simplipy.API( File "/home/pi/gitsrc/B9/simpliGetFirstToken.py", line 56, in <module> asyncio.run(main()) TypeError: __init__() takes 1 positional argument but 3 positional arguments (and 1 keyword-only argument) were given
To Reproduce
Following wiki (https://simplisafe-python.readthedocs.io/en/latest/usage.html) ,I acquired the authorization code, and code verifier.
Run python script in Visual Code in debugger in Raspberry PI
I have python3 version 3.9,2
Here is my code snippet:
async def main() -> None:
settingsDict=get_settings()
print("auth code : ",ss_auth_code)
async with ClientSession() as session:
api = await simplipy.API( <================ Dies here
ss_auth_code,
ss_code_verifier,
session=session
)
print("auth code:",api.auth_state)
asyncio.run(main())
Looks like I forgot to update that section of the documentation. I'll fix that; in the meantime, check out the example script for how to instantiate an API object: https://github.com/bachya/simplisafe-python/blob/dev/examples/test_client_by_auth.py
I switched to the new metho async_from_auth()
and regenerated the auth code and verifier,
Now I see different error : Invalid Credentials"
Do I need to git pull the repo because code changed?
No, the only change was to documentation. How did you generate the auth code and verifier?
I ran the script/setup
I provided the user and password that I use for reaching the portal (https://webapp.simplisafe.com)
I got back the values below , which I passed into async_from_auth() method
===============================================
You are now ready to use the SimpliSafe API!
Authorization Code: xxxxxxxx
Code Verifier: yyyyyyyy
I cannot reproduce—everything works when I plug the values provided by script/setup
into the example script referenced above. I'd ensure you do not include spaces or other characters when pasting the auth code and verifier.
the 2 strings look good to me.
I got the same error running VS Code debug,
and calling from bash command line :python3 simpliGetApiObject.py
Not sure what else to troubleshoot ?
Are you copying the correct code from your browser console at the SimpliSafe website?
Also, what SimpliSafe plan do you have?
I removed the Windows Pin 2FA from my SSafe account.
But I still fall into the SimpliError exception with "Invalid Credentials"
Error happens when instantiating the ssafe client I believe.
This is my code:
async with ClientSession() as session:
logging.basicConfig(level=logging.INFO)
if not SIMPLISAFE_AUTHORIZATION_CODE or not SIMPLISAFE_CODE_VERIFIER:
_LOGGER.error("Missing authentication info")
return
try:
simplisafe = await API.async_from_auth(
SIMPLISAFE_AUTHORIZATION_CODE,
SIMPLISAFE_CODE_VERIFIER,
session=session,
)
refreshtoken = simplisafe.refresh_token <== i never reach this
I got the API object Thanks for your help.