[v7 BUG] REST API not working

Since V7 has come out, I haven’t been able to use the PUT or DELETE functions from the REST API. I get the following error:

Traceback (most recent call last):
File “/home/ubuntu/frappe-bench/apps/frappe/frappe/app.py”, line 58, in application
response = frappe.api.handle()
File “/home/ubuntu/frappe-bench/apps/frappe/frappe/api.py”, line 78, in handle
data = json.loads(frappe.local.form_dict.data)
File “/usr/lib/python2.7/json/init.py”, line 338, in loads
return _default_decoder.decode(s)
File “/usr/lib/python2.7/json/decoder.py”, line 366, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
TypeError: expected string or buffer

This is using code that worked with v6. Also, I’m not even sure what JSON string needs to be decoded with DELETE.

Can anyone replicate this behavior?

@Ben_Cornwell_Mott there is clearly an error with the JSON string your are sending.

I would normally agree with you, but I get the same error when sending a DELETE message, there is no JSON string to be decoded, so why would I get it then?

Also, I’m using code that worked with v6.

@Ben_Cornwell_Mott It works fine for me. Please check

Can you share api call?

I think I had an issue where I wasn’t outputting the latest response from the server. Here is what I’m sending:

PUT to http://erp.mysite.com/api/resource/Timesheet/TS-01001
data={“docstatus”: 2}

Here is what I get back:

Traceback (most recent call last):
File “/home/ubuntu/frappe-bench/apps/frappe/frappe/app.py”, line 58, in application
response = frappe.api.handle()
File “/home/ubuntu/frappe-bench/apps/frappe/frappe/api.py”, line 88, in handle
“data”: doc.save().as_dict()
AttributeError: ‘NoneType’ object has no attribute ‘as_dict’

@rmehta, I think the issue is with a commit you pushed on July 19th, 2016:

https://github.com/frappe/frappe/commit/22c3f7966d7894eb4a047176067b40ce85cfe411#diff-a3f70253d5e0e74b60e2c294dbf6c589

With the new wrapper for save , nothing is returned. This means that the doc.save() call in line 88 of api.py has no return, and the as_dict() is called on nothing, causing the error.

I have created a pull request that should fix this:

https://github.com/frappe/frappe/pull/1900

1 Like