N4S4 / synology-api

A Python wrapper around Synology API
MIT License
384 stars 142 forks source link

KeyError: 'data' #101

Closed jackiezxt closed 2 years ago

jackiezxt commented 2 years ago

synology-api/auth.py line42 in login self._sid = session_request.json()['data']['sid'] KeyError: 'data'

N4S4 commented 2 years ago

Please in order to troubleshoot post your data input

shaft3796 commented 2 years ago

same issue

shaft3796 commented 2 years ago

Nas: DS21Plus

Code used:

from synology_api import filestation

ip = 'xx.xx.xx.xx
port = '5001'
username = 'xxxxxxxxxxxxxxxxxxx'
password = 'xxxxxxxxxxxxxxxxxxx'

fl = filestation.FileStation(ip, port, username, password, secure=True, cert_verify=True, dsm_version=7, debug=True, otp_code=None)

Exception:

Traceback (most recent call last):
  File "x\test.py", line 9, in 
    fl = filestation.FileStation(ip, port, username, password, secure=True, cert_verify=True, dsm_version=7, debug=True, otp_code=None)
  File "x\Python310\lib\site-packages\synology_api\filestation.py", line 34, in __init__
    self.session.login('FileStation')
  File "x\Python310\lib\site-packages\synology_api\auth.py", line 42, in login
    self._sid = session_request.json()['data']['sid']
KeyError: 'data'
shaft3796 commented 2 years ago

Okay so here is a possible cause of the exception:

I modified the login method in auth.Authentication to print session_request, it gave me this:

{'error': {'code': 403, 'errors': {'token': 'xxxxxxxx', 'types': [{'type': 'otp'}]}}, 'success': False}

It seems that I needed an otp password and since I use it it's working fine ! So @jackiezxt I suggest you to do the same to see what is the problem !

N4S4 commented 2 years ago

90% of the times is an initialization/settings problem, which means some settings or parameters might be incorrect and this leads to opening issues for something that users mistake. Thank you @Shaft-3796 for investigating your own issue and solving it!

N4S4 commented 2 years ago

Closed for inactivity