Page 1 of 1

VPN Server JSON-RPC API Python Example

Posted: Sun Jul 28, 2019 1:29 pm
by odianosen

Sort of an entry-level python programmer here.

I want to make use of the new supported JSON-RPC API for a python script I am working on, but unfortunately cannot seem to get my head around how to go about it.

The documentation has examples in TypeScript, C# and JavaScript but nothing on Python. Please can someone help me with some python examples, so I can take it up from there?

Kind regards

Re: VPN Server JSON-RPC API Python Example

Posted: Tue Apr 07, 2020 7:16 am
by nickdsl
Did you find solution?

Re: VPN Server JSON-RPC API Python Example

Posted: Tue Apr 07, 2020 7:42 pm
by nickdsl
I had similar issue.
I write python script.
My example (don't work):

Code: Select all

# working with json
import json
# working with requests
import requests
# urllib3
import urllib3
# for debugging
import pdb

# server url
# api url
API_URL = SERVER_URL + "/api/"
# adminhub
ADMIN_HUB = "" # for admin login leave empty
# server password
# my headers

PARAMS = {"jsonrpc": "2.0", "id": "rpc_call_id", "method": ""}
# disable warnings
MY_PARAMS['method'] = "Test"
#MY_PARAMS['method'] = "GetServerInfo"
MY_PARAMS['params'] = {"IntValue_u32": 0}
#MY_PARAMS['params'] = {}

response =, data=MY_PARAMS, headers=HEADERS, verify=False)
and when i got:
"error": {
"code": 38,
"message": "Error code 38: Parameter is invalid: JSON-RPC Parse Error"
"jsonrpc": "2.0",
"id": "0"

Mistake - data must be string, not dictionary.

I replaced line:

Code: Select all

response =, data=MY_PARAMS, headers=HEADERS, verify=False)

Code: Select all

response =, data=json.loads(MY_PARAMS), headers=HEADERS, verify=False)

and then i got
"result": {
"Int64Value_u64": 0,
"IntValue_u32": 0,
"StrValue_str": "0",
"UniStrValue_utf": ""
"jsonrpc": "2.0",
"id": "rpc_call_id"
You should try same thing.

Re: VPN Server JSON-RPC API Python Example

Posted: Sat Nov 21, 2020 4:36 pm
You should try the following codes, they work for me infact i am trying to implement using Django.

Code: Select all

import requests
import json

username = " "
password = "password_here"
gateway = ""  #server address here

def get_server_info(**params):
	payload = {
	"jsonrpc": "2.0",
	"id": "rpc_call_id",
	"method": "GetServerInfo",
		"params": {
	    "HubName_str": params.get("hubname", None),
	    "Port_u32": params.get("port",None),
		"Enable_bool": params.get("enabled",None)

	headers= {'content-type': 'application/json'}
	response = requests.request("POST", url=gateway, headers=headers, data = json.dumps(payload), 
		verify = False, auth = (username,password))
	data = response.json()

	data = print (response.text)
	return data