Pyhass / Pyhiveapi

A python library to interface with the hive home api
MIT License
24 stars 18 forks source link

[BUG] Code stopped working and get this error pyhiveapi.helper.hive_exceptions.HiveReauthRequired #76

Closed rick165 closed 6 months ago

rick165 commented 6 months ago

Noticed the my code to get hive status has stopped working. I'm using the following method to start the session.

    session = Hive(
        username="username",
        password="password",
    )
    # This time tell the auth object about the device:
    session.auth.device_group_key = 'xxxxxxxx'
    session.auth.device_key = 'xxxxxxxxx'
    session.auth.device_password = 'xxxxxxxxxxxx'

    # Now login - should be challenged with device login
    login = session.login()
    if login.get("ChallengeName") == DEVICE_REQUIRED:
        session.deviceLogin() #Note - this will fail if you do not adapt session.py first - see below!
        #print(session.tokens['tokenData']['token'])
    else:
        print("Are you sure device is registered?")
    session.startSession()

and get the following error. It used to work flawlessly.


2024-03-18 08:00:44.859 | ERROR    | pyhiveapi.hive:exception_handler:44 - -> 
Error in /home/rick/.local/lib/python3.11/site-packages/pyhiveapi/session.py
when running startSession function
on line 507 - raise HiveReauthRequired 
with vars None
Error in sys.excepthook:
Traceback (most recent call last):
  File "/home/rick/.local/lib/python3.11/site-packages/pyhiveapi/hive.py", line 52, in exception_handler
    traceback.print_exc(tb)
  File "/usr/lib/python3.11/traceback.py", line 183, in print_exc
    print_exception(*sys.exc_info(), limit=limit, file=file, chain=chain)
  File "/usr/lib/python3.11/traceback.py", line 124, in print_exception
    te = TracebackException(type(value), value, tb, limit=limit, compact=True)
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/traceback.py", line 690, in __init__
    self.stack = StackSummary._extract_from_extended_frame_gen(
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/traceback.py", line 409, in _extract_from_extended_frame_gen
    if limit >= 0:
       ^^^^^^^^^^
TypeError: '>=' not supported between instances of 'traceback' and 'int'

Original exception was:
Traceback (most recent call last):
  File "/home/rick/scripts/hivecontrol/hivecontrol.py", line 107, in <module>
    hive_session = get_hive_session()
                   ^^^^^^^^^^^^^^^^^^
  File "/home/rick/scripts/hivecontrol/hivecontrol.py", line 48, in get_hive_session
    session.startSession()
  File "/home/rick/.local/lib/python3.11/site-packages/pyhiveapi/session.py", line 507, in startSession
    raise HiveReauthRequired
pyhiveapi.helper.hive_exceptions.HiveReauthRequired
rick165 commented 6 months ago

It seems my Pi-Hole installation was blocking something. After turning it off everything works ok again. Closing issue