I am trying to generate a voucher from Ubiquity UNIFY web portal. It has a API, and there is some ideas to use this with PHP, but I would like to use Python 2.6 to generate.. (I can ofc ourse use other Python versions if this is a must)
My code is:
import urllib, json
import urllib2
import unifi
import os
import requests
def JsonLogin():
payload = {"username" : "myuser","password" : "mypassword"}
r = requests.post("https://ubnt.myserver.com:8443/api/login", data=payload, verify=False)
print r
def JsonApi():
payload = {"cmd":"create-voucher","minutes":1440,"n":1}
r = requests.post("https://ubnt.myserver.com:8443/api/cmd/hotspot", data=payload, verify=False)
print r
JsonLogin();
JsonApi();
My Result is:
<Response [400]>
<Response [401]>
Is there any logic why it returns 400, witch means error... Is this because I sent invalid JSON or is this because the syntax or JSON tags are wrong?