I'd like to change a the password of the guest WIFI on my FritzBox router. For connecting to the FritzBox I use the FritzConnection lib in Python. In general FritzConnection works: I am able to read information from the FritzBox and I am also able to enable or disable the guest WIFI. However, I am facing trouble in changing the password. I can read the password, though.
Here's what I've done so far:
#!/usr/bin/python3
from fritzconnection import FritzConnection
import pprint
pp = pprint.PrettyPrinter(indent=2)
fc=FritzConnection(address='192.168.2.1', password='XYZ', use_tls=True)
#switch guest WIFI off and on again - this works
state = fc.call_action('WLANConfiguration:3', 'GetInfo')
pp.pprint(state)
print("Disable WLAN")
fc.call_action('WLANConfiguration3',
'SetEnable',
arguments={'NewEnable':0})
state = fc.call_action('WLANConfiguration:3', 'GetInfo')
pp.pprint(state)
input("Press Enter to continue...")
print("Enable WLAN")
fc.call_action('WLANConfiguration3',
'SetEnable',
arguments=NewEnable=1)
state = fc.call_action('WLANConfiguration:3', 'GetInfo')
pp.pprint(state)
This code snippet switches the WIFI off and on, and this works fine. Please note that I used 2 different methods of parameter-passing for enabling and disabling. Both work.
Now, when it comes to changing the password I first read the security keys (which works) and then I try to set them anew (which does not work). For reading I do as follows:
securityKeys = fc.call_action('WLANConfiguration:3', 'GetSecurityKeys')
pp.pprint(securityKeys)
For writing first I tried:
fc.call_action('WLANConfiguration:3',
'SetSecurityKeys',
NewKeyPassphrase='BetterPassword')
this results in
fritzconnection.core.exceptions.FritzArgumentError: UPnPError:
errorCode: 402
errorDescription: Invalid Args
I also tried
fc.call_action('WLANConfiguration3',
'SetSecurityKeys',
arguments={'NewKeyPassphrase':'MeinPasswortIstBesser'})
and
fc.call_action('WLANConfiguration:3',
'SetSecurityKeys',
NewWEPKey0='',
NewWEPKey1='',
NewWEPKey2='',
NewWEPKey3='',
NewPreSharedKey='',
NewKeyPassphrase="MeinPasswortIstBesser")
and
securityKeys['NewKeyPassphrase']='MeinPasswortIstBesser'
fc.call_action('WLANConfiguration3',
'SetSecurityKeys',
arguments=securityKeys)
but the result is always the same. Apparently I do something wrong with the parameters, however I cannot say, what it should be. Using the FritzConnection CLI tool tells me the interface:
fritzconnection --ip-address 192.168.2.1 -A 'WLANConfiguration3' 'SetSecurityKeys'
fritzconnection v1.3.4
FRITZ!Box 7590 at http://192.168.2.1
FRITZ!OS: 7.20
Service: WLANConfiguration3
Action: SetSecurityKeys
Parameters:
Name direction data type
NewWEPKey0 -> in string
NewWEPKey1 -> in string
NewWEPKey2 -> in string
NewWEPKey3 -> in string
NewPreSharedKey -> in string
NewKeyPassphrase -> in string
and to my understanding I serve that interface.
Any ideas on what I am doing wrong here?