kbr / fritzconnection

Python-Tool to communicate with the AVM Fritz!Box by the TR-064 protocol and the AHA-HTTP-Interface
MIT License
304 stars 59 forks source link

Status Module: Issue with non matching service names #88

Closed zaphod-pab closed 1 year ago

zaphod-pab commented 3 years ago

Hi, just started playing with this beautiful package, but experience issues on my box. Not sure if this is related to the firmware and what could be an elegant way of dealing with the fact that the names seem to differ on different boxes. Br, R.

Here's an example:

:~ $ fritzstatus -i ADDR -p PASSW

fritzconnection v1.4.2
FRITZ!Box 6591 Cable (lgi) at http://192.168.178.1
FRITZ!OS: 7.22

FritzStatus:

    is linked             : unsupported attribute "is_linked"
    is connected          : unsupported attribute "is_connected"
    external ip (v4)      : unsupported attribute "external_ip"
    external ip (v6)      : unsupported attribute "external_ipv6"
    internal ipv6-prefix  : unsupported attribute "ipv6_prefix"
    uptime                : unsupported attribute "str_uptime"
    bytes send            : unsupported attribute "bytes_sent"
    bytes received        : unsupported attribute "bytes_received"
    max. bit rate         : unsupported attribute "str_max_bit_rate"

I managed to track this to the fact that the services needed to request the status items are named differently from what fritzconnection/fritzconnection/lib/fritzstatus.py assumes. E.g. WANIPConn is called WANIPConnection in my case.

See the check below.

>>> fc.call_action("WANIPConn", "GetStatusInfo")
Traceback (most recent call last):
  File "/home/pi/.local/lib/python3.7/site-packages/fritzconnection/core/fritzconnection.py", line 224, in call_action
    service = self.device_manager.services[service_name]
KeyError: 'WANIPConn1'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/pi/.local/lib/python3.7/site-packages/fritzconnection/core/fritzconnection.py", line 226, in call_action
    raise FritzServiceError(f'unknown service: "{service_name}"')
fritzconnection.core.exceptions.FritzServiceError: unknown service: "WANIPConn1"

>>> fc.call_action("WANIPConnection", "GetStatusInfo")
{'NewConnectionStatus': 'Connected', 'NewLastConnectionError': 'ERROR_NONE', 'NewUptime': 312243}

Here's an overview of what my box reports:

fritzconnection v1.4.2
FRITZ!Box 6591 Cable (lgi) at http://192.168.178.1
FRITZ!OS: 7.22

Servicenames:
                    DeviceInfo1
                    DeviceConfig1
                    Layer3Forwarding1
                    LANConfigSecurity1
                    ManagementServer1
                    Time1
                    UserInterface1
                    X_AVM-DE_Storage1
                    X_AVM-DE_WebDAVClient1
                    X_AVM-DE_UPnP1
                    X_AVM-DE_Speedtest1
                    X_AVM-DE_RemoteAccess1
                    X_AVM-DE_MyFritz1
                    X_VoIP1
                    X_AVM-DE_OnTel1
                    X_AVM-DE_Dect1
                    X_AVM-DE_TAM1
                    X_AVM-DE_AppSetup1
                    X_AVM-DE_Homeauto1
                    X_AVM-DE_Homeplug1
                    X_AVM-DE_Filelinks1
                    X_AVM-DE_Auth1
                    X_AVM-DE_HostFilter1
                    WLANConfiguration1
                    WLANConfiguration2
                    WLANConfiguration3
                    Hosts1
                    LANEthernetInterfaceConfig1
                    LANHostConfigManagement1
                    WANCommonInterfaceConfig1
                    WANDSLInterfaceConfig1
                    WANDSLLinkConfig1
                    WANEthernetLinkConfig1
                    WANPPPConnection1
                    WANIPConnection1
kbr commented 3 years ago

Boxes for cable-connections provide a subset of services for dsl-boxes. Historically fritzconnection is developed with dsl-boxes in mind (here is a service listing of my dsl-box):

fritzconnection v1.4.2
FRITZ!Box 7590 at http://192.168.178.1
FRITZ!OS: 7.21

Servicenames:
                    any1
                    WANCommonIFC1
                    WANDSLLinkC1
                    WANIPConn1
                    WANIPv6Firewall1
                    DeviceInfo1
                    DeviceConfig1
                    Layer3Forwarding1
                    LANConfigSecurity1
                    ManagementServer1
                    Time1
                    UserInterface1
                    X_AVM-DE_Storage1
                    X_AVM-DE_WebDAVClient1
                    X_AVM-DE_UPnP1
                    X_AVM-DE_Speedtest1
                    X_AVM-DE_RemoteAccess1
                    X_AVM-DE_MyFritz1
                    X_VoIP1
                    X_AVM-DE_OnTel1
                    X_AVM-DE_Dect1
                    X_AVM-DE_TAM1
                    X_AVM-DE_AppSetup1
                    X_AVM-DE_Homeauto1
                    X_AVM-DE_Homeplug1
                    X_AVM-DE_Filelinks1
                    X_AVM-DE_Auth1
                    X_AVM-DE_HostFilter1
                    WLANConfiguration1
                    WLANConfiguration2
                    WLANConfiguration3
                    Hosts1
                    LANEthernetInterfaceConfig1
                    LANHostConfigManagement1
                    WANCommonInterfaceConfig1
                    WANDSLInterfaceConfig1
                    WANDSLLinkConfig1
                    WANEthernetLinkConfig1
                    WANPPPConnection1
                    WANIPConnection1

Seems to be that the fritzstatus module runs into this issue.

Thank you for reporting: would be a nice idea for the next version to write a check for cable models and adapt the fritzstatus module accordingly – at least for a working subset.

gtrooper commented 3 years ago

Hi kbr, I am trying to use the Servicename DeviceConfig1 to Reboot my fritzbox 7590 V 7.21 via Actionname Reboot but it does not work. This is the command I use to reboot: fritzconnection -i 192.168.70.1 -p 123456 -A DeviceConfig1 Reboot

Am I missing something ? Thanks in advance !

kbr commented 3 years ago

The commandline interface is for the API inspection. To execute an action on a given service you have to use the call_action method, i.e. :

from fritzconnection import FritzConnection

fc = FritzConnection(<your parameters here>)
fc.call_action("DeviceConfig1", "Reboot")
gtrooper commented 3 years ago

Could you please tell me where I need to run this function ? In terminal does not run. I have read the instructions but I cant find where I need to type this function. Thank You !

kbr commented 3 years ago

You can use the interactive python interpreter to tun the code or implement this in a python module.

kbr commented 1 year ago

I suppose this is not a bug. If the topic pops up again and is not because of different router models, please open a new issue.