persandstrom / python-verisure

A python module for reading and changing status of verisure devices through verisure app api.
MIT License
134 stars 42 forks source link

401 - Unauthorized #166

Closed BalancingComic closed 1 year ago

BalancingComic commented 1 year ago

Used the example_usage.py and added a while loop that polls arm_status every 5 minutes. It loops for about 3 iterations and returns an exception:

Invalid response, status code: 401 - Data: 401 Unauthorized

Code:

'# example_usage.py

import verisure import time

USERNAME = *** PASSWORD = **** report_intervall = 300

session = verisure.Session(USERNAME, PASSWORD)

'# Login without Multifactor Authentication '#installations = session.login() '# Or with Multicator Authentication, check your phone and mailbox session.request_mfa() installations = session.validate_mfa(input("code:"))

'# Get the giid for your installation giids = { inst['alias']: inst['giid'] for inst in installations['data']['account']['installations'] } print(giids) '# {'MY STREET': '123456789000'}

'# Set the giid session.set_giid(giids["****"])

while True: try: arm_state = session.request(session.arm_state()) print(arm_state) time.sleep(report_intervall) except Exception as e: print(e)

Response:

code:** '** {'Road': 'giids no.'} {'data': {'installation': {'armState': {'type': None, 'statusType': 'DISARMED', 'date': '2023-04-13T05:04:58.000Z', 'name': ' *', 'changedVia': 'CODE', 'typename': 'ArmState'}, 'typename': 'Installation'}}} {'data': {'installation': {'armState': {'type': None, 'statusType': 'DISARMED', 'date': '2023-04-13T05:04:58.000Z', 'name': ' *', 'changedVia': 'CODE', 'typename': 'ArmState'}, 'typename': 'Installation'}}} {'data': {'installation': {'armState': {'type': None, 'statusType': 'DISARMED', 'date': '2023-04-13T05:04:58.000Z', 'name': '** *****', 'changedVia': 'CODE', 'typename': 'ArmState'}, 'typename': 'Installation'}}} Invalid response, status code: 401 - Data: 401 Unauthorized

persandstrom commented 1 year ago

Hi,

Did you ever call update_cookie? that needs to be done every 15th minute

BalancingComic commented 1 year ago

Ok, Thanks for the answer. So its needed that often. Missed that line in the code.