maas post returns "BAD request error"

Bug #1499190 reported by muralidharan
14
This bug affects 2 people
Affects Status Importance Assigned to Milestone
MAAS
Invalid
Undecided
Unassigned

Bug Description

I am trying to execute a post request on MAAS.

That is what I need to do here is have to POST some details to MAAS using MAAS API.

So that I have followed the MAAS API documentation.

Using the same I can be able to process GET requests.

In the mean time when I am attempting to do a POST request I am getting error as follows:

<pre>
  File "vag_1.py", line 105, in <module>
    maas_access.post(u"users/", "", **params)
  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.
</pre>

My code for post is as follows:

<pre>

argument_parser = argparse.ArgumentParser(description=__doc__)
argument_parser.add_argument("username", type=unicode)
argument_parser.add_argument("email", type=unicode)
argument_parser.add_argument("password", type=unicode)
argument_parser.add_argument("is_superuser", type=unicode)

params = {"username": "newuser", "email": "<email address hidden>", "password": "newuser", "is_superuser": "1"}

maas_access.post(u"users/", "", **params)

</pre>

What I am doing wrong here.

Please let me know the proper way for doing the same.

Atleast provide with me any proper logs to trace the same.

Tags: maas-api
description: updated
Revision history for this message
muralidharan (muraliselva-10) wrote :

I can get the correct result for normal POST without data.

For the following request:

# creating authorization token
maas_access.post(u"account/", "create_authorisation_token")

But in case of POST request like above I amalways getting an error

Revision history for this message
Mike Pontillo (mpontillo) wrote :

Thanks for your interest in MAAS.

Unfortunately, the bug tracker is not the appropriate venue to discuss this type of support request.

I suggest you use Wireshark (or a similar tool) to compare the results from the "maas" CLI command with the results of your script. (Or simply use the "maas" command directly.)

Changed in maas:
status: New → Invalid
Revision history for this message
muralidharan (muraliselva-10) wrote :

Ok then where should I reach to discuss above issue.

Revision history for this message
Mike Pontillo (mpontillo) wrote :

You might try stackoverflow and/or askubuntu, but they will most likely expect you to do more research to fully narrow down the issue before asking for help. Again, I would use Wireshark to compare the POST request from the (already working) 'maas' CLI command to that which your code generates. Also, you can find the source code for the official MAAS CLI here:

https://bazaar.launchpad.net/~maas-committers/maas/1.8/files/head:/src/maascli/

I will not be able to provide further assistance on this bug. Good luck!

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Duplicates of this bug

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.