POST request using python-maas-client
| Affects | Status | Importance | Assigned to | Milestone | |
|---|---|---|---|---|---|
| | MAAS |
Undecided
|
Unassigned | ||
Bug Description
Hi,
How can we do the post request to maas api using the python-maas-client.
I try to get the details from maas api usign the maas-client by the following code.
print maas_access.
print maas_access.
But when i try to post a request I am getting the error.
data = ({
"username": "testuser",
"email": "<email address hidden>"
});
maas_access.
Traceback (most recent call last):
File "api.py", line 117, in <module>
maas_
File "/usr/lib/
path, kwargs, as_json=as_json)
File "/usr/lib/
url += '?' + urlencode([('op', op)])
File "/usr/lib/
for name, value in data)
File "/usr/lib/
for name, value in data)
File "/usr/lib/
string.
File "/usr/lib/
return quote(s, safe)
File "/usr/lib/
if not s.rstrip(safe):
AttributeError: 'dict' object has no attribute 'rstrip'
Is I am missing some thing or the data that i providing is wrong ?
Please help me
| Binoy M V (binoy-mv-s) wrote : | #1 |
| Gavin Panella (allenap) wrote : | #2 |
Try with:
data = {
"username": "murali",
"email": "<email address hidden>"
}
I think it's choking on the integer.
| Changed in maas: | |
| status: | New → Invalid |
| Binoy M V (binoy-mv) wrote : | #3 |
No luck, getting same error from the code
data = {
"username": "murali",
"email": "<email address hidden>"
}
maas_access.
File "/usr/lib/
path, kwargs, as_json=as_json)
File "/usr/lib/
url += '?' + urlencode([('op', op)])
File "/usr/lib/
for name, value in data)
File "/usr/lib/
for name, value in data)
File "/usr/lib/
string.
File "/usr/lib/
return quote(s, safe)
File "/usr/lib/
if not s.rstrip(safe):
AttributeError: 'dict' object has no attribute 'rstrip'
| Changed in maas: | |
| status: | Invalid → New |
| Gavin Panella (allenap) wrote : | #4 |
The second argument to `post` is the operation:
def post(self, path, op, as_json=False, **kwargs):
"""Dispatch POST method `op` on `path`, with the given parameters.
:param as_json: Instead of POSTing the content as multipart/form-data
POST it as application/json
:return: The result of the dispatch_query call on the dispatcher.
"""
Pass the empty string if you want a plain POST. Try the following:
maas_
The `apiclient` library is bare-bones; it doesn't help much. We are
working on a better client library. In the meantime, sorry, this is
harder than it should be :-/
| Changed in maas: | |
| status: | New → Invalid |
| Binoy M V (binoy-mv) wrote : | #5 |
Thank you Gavin.
My aim is to send a post to maas. Is there any way to do so ?
Is there any example that we can see, how to pass the data into maas api using post ?
| Changed in maas: | |
| status: | Invalid → In Progress |
| status: | In Progress → Incomplete |
| Christian Reis (kiko) wrote : | #6 |
Binoy, can you ask a question using askubuntu.com under MAAS explaining what you are trying to do? This doesn't look like it's a bug in MAAS.
| Changed in maas: | |
| status: | Incomplete → Invalid |
| Nicola Senno (nsenno) wrote : | #7 |
for the record here is an example on how to use the POST:
https:/
| Blake Rouse (blake-rouse) wrote : | #8 |
I would recommend using the official python library for MAAS to work with the API.


I tried with
data = {
"is_superuser" : 1,
"username": "murali",
"email": "<email address hidden>"
}
Also getting same error. access. post(u" users/" , data) python2. 7/dist- packages/ apiclient/ maas_client. py", line 248, in post python2. 7/dist- packages/ apiclient/ maas_client. py", line 218, in _formulate_change python2. 7/dist- packages/ apiclient/ utils.py" , line 48, in urlencode python2. 7/dist- packages/ apiclient/ utils.py" , line 48, in <genexpr> python2. 7/dist- packages/ apiclient/ utils.py" , line 45, in <lambda> encode( "utf-8" ) if isinstance(string, unicode) else string) python2. 7/urllib. py", line 1295, in quote_plus python2. 7/urllib. py", line 1286, in quote
]
Traceback (most recent call last):
File "api.py", line 120, in <module>
maas_
File "/usr/lib/
path, kwargs, as_json=as_json)
File "/usr/lib/
url += '?' + urlencode([('op', op)])
File "/usr/lib/
for name, value in data)
File "/usr/lib/
for name, value in data)
File "/usr/lib/
string.
File "/usr/lib/
return quote(s, safe)
File "/usr/lib/
if not s.rstrip(safe):
AttributeError: 'dict' object has no attribute 'rstrip'