0
我正在使用Python API來處理對MongoDB的REST調用。該API基於Kule(因此包括Bottle和PyMongo模塊)。前端使用node.js構建。我一直在使用API,前端和MongoDB在不同端口上開發和測試本地主機。node.js中的POST失敗
我已經設置了API並一直試圖讓CRUD請求正常工作。我可以從Python腳本以及運行在Apache服務器上的Javascript中獲得這些工作。但是,當我將相同的代碼添加到前端時,GET工作,但POST失敗,出現500錯誤。
此POST代碼工作在Apache服務器上:
var myrequest=new XMLHttpRequest();
myrequest.onreadystatechange=function(){
if (myrequest.readyState==4){
if (myrequest.status==201){
alert(myrequest.responseText);
} else{
alert("An error has occured making the request");
}
}
}
myrequest.open("POST", "http://localhost:8080/items", true);
myrequest.setRequestHeader("Content-type", "application/json;charset=UTF-8");
myrequest.send(JSON.stringify({'name' : 'Name', 'description' : 'Description'}));
當我添加這前端,我從庫勒得到以下回溯:
Traceback (most recent call last):
File "C:\Python27\lib\site-packages\bottle.py", line 764, in _handle
return route.call(**args)
File "C:\Python27\lib\site-packages\bottle.py", line 1625, in wrapper
rv = callback(*a, **ka)
File "C:\Python27\lib\site-packages\bottle.py", line 1575, in wrapper
rv = callback(*a, **ka)
File "C:\Python27\lib\site-packages\kule\kule.py", line 64, in post_list
inserted = collection.insert(request.json)
File "C:\Python27\lib\site-packages\pymongo\collection.py", line 351, in insert
docs = [self.__database._fix_incoming(doc, self) for doc in docs]
TypeError: 'NoneType' object is not iterable
127.0.0.1 - - [24/Jun/2014 07:53:40] "POST /scenarios HTTP/1.1" 500 50
所以,我是什麼做錯了?爲什麼Javascript會在node.js中斷?我有GET工作,但POST失敗。爲什麼?
謝謝!