Page 1 of 1

Trying to use API via Python, getting blank result

Posted: Mon Apr 16, 2018 10:16 pm
by revelnode
Ok, so I have tried this many ways, via URL directly, using username and password or API hash, and every time I try, I get a blank result.

Here is the latest attempt to get it to work:

Code: Select all

import urllib2
import json
import os

vst_url = "https://myserver.com:8083/api/"
vst_hash = "my_really_long_hash_api_key"
vst_cmd = "v-list-users"

request = urllib2.Request(vst_url, headers={"hash":vst_hash, "cmd":vst_cmd, "returncode":"yes", "arg1":"json"})
result = json.load(urllib2.urlopen(request))
print result
I have tried it other ways and gotten nothing in return. Do you have to enable API? Is there a log I can check to see what error there was if there is one? (normally it is displayed on the screen, but nothing is in this case)

Re: Trying to use API via Python, getting blank result

Posted: Mon Apr 16, 2018 11:00 pm
by revelnode
The odd thing... It works in PHP... but I cannot seem to emulate it in Python... anyone had any success?

Re: Trying to use API via Python, getting blank result

Posted: Tue Apr 17, 2018 6:37 pm
by revelnode
Ok, for all those wondering how to do it

Code: Select all

import requests

url = "https://srv1.serversmadeeasy.com:8083/api/index.php"
user = "admin"
password = "your-password-goes-here"
cmd = "v-list-user"
arg1 = "username"
arg2 = "json"

data = {'user':user, 'password':password, 'cmd':cmd, 'arg1':arg1, 'arg2':arg2}

resp = requests.post(url, data)
print resp.json()
I tried 50 different ways, and all of a sudden, this one worked.
There is NO documentation on this, Time for a Blog post.