Como podemos fazer o post request para o maas api usando o python-maas-client.
Estou obtendo os detalhes do maas api usando o maas-client pelo seguinte código.
print maas_access.get(u"networks").read()
print maas_access.get(u"users").read()
Mas quando tento postar uma solicitação, recebo o erro. código está abaixo
data = {'username':'murali','email':'[email protected]','password':'murali','is_superuser': 0}
maas_access.post(u"users/", "new", data)
Traceback (most recent call last):
File "api.py", line 48, in <module>
maas_access.post(u"users/", "new", data)
File "/usr/lib/python2.7/dist-packages/apiclient/maas_client.py", line 250, in post
url, method="POST", headers=headers, data=body)
File "/usr/lib/python2.7/dist-packages/apiclient/maas_client.py", line 116, in dispatch_query
res = urllib2.urlopen(req)
File "/usr/lib/python2.7/urllib2.py", line 127, in urlopen
return _opener.open(url, data, timeout)
File "/usr/lib/python2.7/urllib2.py", line 410, in open
response = meth(req, response)
File "/usr/lib/python2.7/urllib2.py", line 523, in http_response
'http', request, response, code, msg, hdrs)
File "/usr/lib/python2.7/urllib2.py", line 448, in error
return self._call_chain(*args)
File "/usr/lib/python2.7/urllib2.py", line 382, in _call_chain
result = func(*args)
File "/usr/lib/python2.7/urllib2.py", line 531, in http_error_default
raise HTTPError(req.get_full_url(), code, msg, hdrs, fp)
urllib2.HTTPError: HTTP Error 400: BAD REQUEST
e se eu usar
data = {'username':'murali','email':'[email protected]','password':'murali','is_superuser': 0}
maas_access.post(u"users/", data)
Traceback (most recent call last):
File "api.py", line 49, in <module>
maas_access.post(u"users/", data)
File "/usr/lib/python2.7/dist-packages/apiclient/maas_client.py", line 248, in post
path, kwargs, as_json=as_json)
File "/usr/lib/python2.7/dist-packages/apiclient/maas_client.py", line 218, in _formulate_change
url += '?' + urlencode([('op', op)])
File "/usr/lib/python2.7/dist-packages/apiclient/utils.py", line 48, in urlencode
for name, value in data)
File "/usr/lib/python2.7/dist-packages/apiclient/utils.py", line 48, in <genexpr>
for name, value in data)
File "/usr/lib/python2.7/dist-packages/apiclient/utils.py", line 45, in <lambda>
string.encode("utf-8") if isinstance(string, unicode) else string)
File "/usr/lib/python2.7/urllib.py", line 1295, in quote_plus
return quote(s, safe)
File "/usr/lib/python2.7/urllib.py", line 1286, in quote
if not s.rstrip(safe):
AttributeError: 'dict' object has no attribute 'rstrip'
Estou perdendo alguma coisa ou os dados que estou fornecendo estão errados?
Por favor me ajude