【发布时间】:2015-11-04 09:37:59
【问题描述】:
我在尝试通过 Apache 服务器访问 Bottle 的 REST API 时遇到此类型错误,但它与 Bottle 的 WSGI 服务器 可以正常工作。
MongoDB示例数据:
"_id" : ObjectId("55c4f21782f2811a08b7ddbb"),
"TestName" : "TestName1",
"Results" : [
{
"Test" : "abc",
"Log" : "Log information"
},
{
"Test" : "xyz",
"Log" : "Log information"
},
]
我只想获取 Results.Test="abc" 的那些记录/子文档
我的 Bottle API 代码:
@route('/TestSampleApi',method='GET')
def GetTestData():
#request.json will have data passed in url
pipe = [
{"$match":{"Results": {"$elemMatch": {'Test':'abc'}}}},
{ "$unwind" :"$Results"},
{ "$match": { "Results.Test":'abc'}},
{ "$group" : { "_id" : "$_id", "Results" : { "$addToSet" : "$Results" } }}
]
res = collection.aggregate(pipeline=pipe)
get_record=res['result'] #getting TypeError in this line
response.set_header('Content-Type', 'application/json')
return dumps(get_record, indent=4)
上面的代码可以正常工作
curl -i GET "http://localhost:8080/TestSampleApi?Test=abc"
但不适用于 Apache:
curl -i GET "http://HOST_NAME/TestSampleApi?Test=abc"
【问题讨论】:
标签: python apache mongodb pymongo bottle