Hello everyone , I found a bug in api.py but I’m not sure is it bug or not.
I have created API with PHP which is connected with Frappe/ERPNEXT ,I tried to insert new lead but I got error
Traceback (most recent call last):\n File "/home/frappe/frappe-bench/apps/frappe/frappe/app.py", line 66, in application\n response = frappe.api.handle()\n File "/home/frappe/frappe-bench/apps/frappe/frappe/api.py", line 117, in handle\n data = json.loads(frappe.local.form_dict.data)\n File "/usr/lib/python3.5/json/init.py", line 312, in loads\n s.class.name))\nTypeError: the JSON object must be str, not ‘bytes’\n
Firstly I thought it’s about my request, I checked with different post fields but i had always same error.
what i tried with curl :
curl_setopt($ch, CURLOPT_POSTFIELDS, array('data' => json_encode($params['data'])));
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($params['data']));
curl_setopt($ch, CURLOPT_POSTFIELDS, '{"lead_name":"Sercan Tarakçı","email_id":"Sercan Tarakçı","source":"Campaign"}');
but it didnt work. Then i think that maybe it’s in api.py , I opened line 117
if frappe.local.request.method=="POST":
data = json.loads(frappe.local.form_dict.data)
data.update({
"doctype": doctype
})
frappe.local.response.update({
"data": frappe.get_doc(data).insert().as_dict()
})
frappe.db.commit()
I changed this line
data = json.loads(frappe.local.form_dict.data)
with this simple trick:
data = json.loads(frappe.local.form_dict.data.decode('utf-8'))
all my request works really fine now.Can someone explain is problem in my curl request or in python code?