maas 2.2 api returning malformed data
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
MAAS |
Invalid
|
Undecided
|
Unassigned |
Bug Description
Hi I'm using python3 to query maas by api and most of them time I'm getting valid http/json data back from lib request. However, sometimes the data that I get back from the maas api is malformed.
here is the python script I'm using:
```
from requests_oauthlib import OAuth1 as oauth
import requests
import json
client_key = 'my_client_key'
client_secret = ''
res_key = 'my_resource_key'
res_secret = 'my_resource_
def myq(url='http://
headeroauth = oauth(client_key, client_secret, res_key,
res_secret, signature_type = 'auth_header')
r = requests.
return r
r = myq(uri=
try:
machine = yaml.load(r.text)
m = {
}
print('good:', r,dir(r))
except Exception:
print('bad:', r, dir(r))
print(r.text)
```
also the librequests json object from the returned query throws the following exception if I try to use that as well when I get a malformed response.
ie
```
r = myq(uri=
machine = r.json()
Traceback (most recent call last):
File "./pyapi.py", line 51, in <module>
machine = r.json()
File "/home/
return complexjson.
File "/usr/lib/
return _default_
File "/usr/lib/
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "/usr/lib/
raise JSONDecodeError
json.decoder.
```
I don't see any errors in any of the mass log files or syslog.
I think this is a duplicate of an existing bug. (I'll link it if I find it.) You probably need to set an 'Accept' header to get consistent results. Long story short: MAAS makes use of a Python library that has some undefined behavior when you don't define one in your request, such as:
Accept: application/json