Vesta Control Panel - Forum

Community Forum

Skip to content

Advanced search
  • Quick links
    • Main site
    • Github repo
    • Google Search
  • FAQ
  • Login
  • Register
  • Board index Dev Section Scripting / API
  • Search

Trying to use API via Python, getting blank result

Questions regarding the API
Application Programming Interface
Post Reply
  • Print view
Advanced search
3 posts • Page 1 of 1
revelnode
Posts: 22
Joined: Thu Jan 19, 2017 8:54 pm

Os: CentOS 6x
Web: apache
Trying to use API via Python, getting blank result
  • Quote

Post by revelnode » Mon Apr 16, 2018 10:16 pm

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)
Top

revelnode
Posts: 22
Joined: Thu Jan 19, 2017 8:54 pm

Os: CentOS 6x
Web: apache
Re: Trying to use API via Python, getting blank result
  • Quote

Post by revelnode » Mon Apr 16, 2018 11:00 pm

The odd thing... It works in PHP... but I cannot seem to emulate it in Python... anyone had any success?
Top

revelnode
Posts: 22
Joined: Thu Jan 19, 2017 8:54 pm

Os: CentOS 6x
Web: apache
Re: Trying to use API via Python, getting blank result
  • Quote

Post by revelnode » Tue Apr 17, 2018 6:37 pm

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.
Top


Post Reply
  • Print view

3 posts • Page 1 of 1

Return to “Scripting / API”



  • Board index
  • All times are UTC
  • Delete all board cookies
  • The team
Powered by phpBB® Forum Software © phpBB Limited
*Original Author: Brad Veryard
*Updated to 3.2 by MannixMD
 

 

Login  •  Register

I forgot my password