[solved (sort of)] Rpc call returns 403 using auth token

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={}):
        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:
    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

I've created an ACL but it still doesn't work.
meanwhile I've tried python-ubus and this works :smiley:

If you consider your problem solved, please mark the topic with [Solved]

can you tell me how to use python-ubus?

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.