Hello,
I hope this is the right place for my question.
I am having some difficulties using the API with python.
Does anyone here have experience using Peplink API with python?
The Python package that calls API is - request.
I managed to login into peplink from python using:
import requests
url = ‘https’: //192.168.1.1//
url1 = url + api/login?username=username&password=password’
response = requests.get(url1)
print(response.json())
– { “stat”: “ok”, “response”: { “permission”: { “GET”: 0, “POST”: 0 } }
I also mannaged to change permission using POST
response = requests.post(url1, {“response”: {“permission”: {“GET”: 1, “POST”: 1}}})
– { “stat”: “ok”, “response”: { “permission”: { “GET”: 1, “POST”: 1 } }
The next step after login was to try the desirable URL according to the documentation:
url2 = url + /api/status.wan.connection?id=1 2’
response = requests.get(url2)
print(response.json())
according to the documentation I should expect:
– { “stat”: “ok”, “response”: { “1”: { “name”: “CUST WAN 1”, “enable”: true, “asLan”: false, “message”: “Connected”, “uptime”: 27037017, “type”: “ethernet”, “virtualType”: “ethernet”, “priority”: 0, “ip”: “192.168.123.144”, “statusLed”: “green”, “mask”: 24, “gateway”: “12.23.34.0”, “method”: “dhcp”, “mode”: “NAT”, “dns”: [ “12.22.32.12”, “12.34.67.89” ], “mtu”: 576 }, “2”: { “name”: “WAN2”, “enable”: true, “asLan”: false, “message”: “No Cable Detected”, “uptime”: 27066417, “type”: “ethernet”, “virtualType”: “ethernet”, “priority”: 0, “statusLed”: “red”, “method”: “static”, “mode”: “IP Forwarding”, “mtu”: 1440 }, “order”: [ 1, 2 ] } }
but what I get is:
– {“stat”: “fail”, “code” :“401”, “message”: “unauthorized”}
Any chance anyone might help me fix that?
kind regards,
Roy