Hi guys, I'm trying to use rpc but it returns 403.
the token is correctly returned using the first part of the python script at the end of my post.
I'm on LEDE Reboot SNAPSHOT r5120-8464d2f64a / LuCI Master (git-17.294.24601-59a4e40).
curl -i -X POST -d '{"method":"get", "params":["network", "wan", "password"]}' http://********/cgi-bin/luci/rpc/uci\?auth\=xxxxxxxxxxxxxxxxxxxxxxxxxxxx
HTTP/1.1 403 Forbidden
Connection: close
Transfer-Encoding: chunked
if you want to know I'm trying to make this python script:
#!/usr/bin/env python3
import json
import requests
#from requests.auth import HTTPBasicAuth
url = "http://*******:80/cgi-bin/luci/rpc/"
headers = {'content-type': 'application/json'}
auth = None
def rpc_call(url, library, payload, params={}):
try:
response = requests.post(url + library, data=json.dumps(payload), params=params, headers=headers) #, auth=auth)
print("url: " + response.url)
print ("res: " + response.text)
return json.loads(response.text)
except Exception as e:
print(e)
pass
return None
library = 'auth'
method = 'login'
method_params = ['root','*********************']
payload = {"method": method, "params": method_params}
token = rpc_call(url, library, payload)['result']
print("token: ", token) # this works
library = 'ipkg'
params = {'auth': token}
method = 'installed'
method_params = ["luci-admin-rpc"]
payload = {"method": method, "params": method_params}
res = rpc_call(url, library, payload, params)
this is what returns:
url: http://*****:80/cgi-bin/luci/rpc/auth
res: {"id":null,"result":"qweryiuopqweryiuopeqwertyiuopqwer","error":null}
token: qweryiuopqweryiuopeqwertyiuopqwer
url: http://*****:80/cgi-bin/luci/rpc/ipkg?auth=qweryiuopqweryiuopeqwertyiuopqwer
res: