Hi I was trying to create a python connector for creating users in hestia, while connecting to the API I’m getting some error like this
import requests
from urllib.parse import urlencode
Admin Credentials
hst_hostname = ‘ip’
hst_port = 8083
hst_username = ‘admin’
hst_password = ‘password’
hst_returncode = ‘yes’
hst_command = ‘v-add-user’
New account details
username = ‘demo’
password = ‘demo’
email = ‘[email protected]’
package = ‘default’
first_name = ‘Demo’
last_name = ‘M’
Prepare data for API request
data = {
‘hash’: ‘access key’,
‘user’: hst_username,
‘password’: hst_password,
‘returncode’: hst_returncode,
‘cmd’: hst_command,
‘arg1’: username,
‘arg2’: password,
‘arg3’: email,
‘arg4’: package,
‘arg5’: first_name,
‘arg6’: last_name
}
URL encode the data
encoded_data = urlencode(data)
Send POST request to HestiaCP API
url = f’https://{hst_hostname}:{hst_port}/api/’
print(“url>>>>>>”, url)
try:
response = requests.post(url, data=encoded_data, verify=False)
print(f"Request data: {encoded_data}“)
print(f"Response status code: {response.status_code}”)
print(f"Response text: {response.text}“)
print(response.text)
print(“0 means successful”)
except requests.exceptions.RequestException as e:
print(f"Error: {e}”)
error:
Response status code: 405
Response text: Error: data received is null or invalid, check REST API | Hestia Control Panel
Error: data received is null or invalid, check REST API | Hestia Control Panel
0 means successful
Process finished with exit code 0