N4S4 / synology-api

A Python wrapper around Synology API
MIT License
398 stars 145 forks source link

`shutdown` request from SYNO.Core.System not working properly #133

Closed grdleo closed 2 months ago

grdleo commented 1 year ago

shutdown request from SYNO.Core.System does not work depending on version request parameter

Hardware: DS218j

>>> from synology_api import core_sys_info
session = core_sys_info.SysInfo('my-nas', 'port', 'user', 'password', secure=False, cert_verify=True, dsm_version=7, debug=False, otp_code=None)
>>> session.shutdown()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/synology_api/core_sys_info.py", line 536, in shutdown
    return self.request_data(api_name, api_path, req_param)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/synology_api/auth.py", line 299, in request_data
    raise CoreSysInfoError(error_code=error_code)
synology_api.exceptions.CoreSysInfoError

Looking inside the code, I see the request parameters are made like this:

def shutdown(self):
        api_name = 'SYNO.Core.System'
        info = self.core_list[api_name]
        api_path = info['path']
        req_param = {'version': info['maxVersion'], 'method': 'shutdown'}

        return self.request_data(api_name, api_path, req_param)

I have found out that using a different version request parameter, it works

>>> session.core_list["SYNO.Core.System"]
{'maxVersion': 3, 'minVersion': 1, 'path': 'entry.cgi', 'requestFormat': 'JSON'}
>>> session.core_list["SYNO.Core.System"]["maxVersion"] = 1
>>> session.core_list["SYNO.Core.System"]
{'maxVersion': 1, 'minVersion': 1, 'path': 'entry.cgi', 'requestFormat': 'JSON'}
>>> session.shutdown()
{'data': {}, 'success': True}

I bet the problem is from Synology's side... Is it because of my hardware that shutdown does not work on this version parameter? Is there a more convenient way to change this version parameter?

N4S4 commented 1 year ago

Hi,

There is no more convenient way unfortunately,

You could just set version:1 as below

def shutdown(self):
        api_name = 'SYNO.Core.System'
        info = self.core_list[api_name]
        api_path = info['path']
        req_param = {'version': 1, 'method': 'shutdown'}

        return self.request_data(api_name, api_path, req_param)

Maybe it is from synology side, the max version should work, but apparently it doesn't for you. If more issue will be reported I will integrate a way to be able to modify it

N4S4 commented 1 year ago

What DSM7 version you have?

grdleo commented 1 year ago

What DSM7 version you have?

Thank you for your reply. DSM 7.1-42661 Update 4

N4S4 commented 10 months ago

Hi, I was looking at the issue, pulling the list from NAS I see SYNO.Core.System': {'maxVersion': 3, 'minVersion': 1, 'path': 'entry.cgi'} where maxVersion is 3 for me. however I did not encounter the issue. Is it still happening? I was thinking to add the possibility to change max min version only for this function.

N4S4 commented 2 months ago

added possibility to change version in PR #175