您好, 欢迎来到 !    登录 | 注册 | | 设为首页 | 收藏本站

Python / Bottle / MongoDB:不支持的响应类型:

5b51 2022/1/14 8:21:12 python 字数 2055 阅读 476 来源 www.jb51.cc/python

@route('/locations', method='GET') def get_location(): entity = db['locations'].find({'coordinate2d': {'$near': [37.871593, -122.272747]}}).limit(3) if not entity:

概述

@route('/locations',method='GET')
def get_location():
    entity = db['locations'].find({'coordinate2d': {'$near': [37.871593,-122.272747]}}).limit(3)
    if not entity:
        abort(404,'No nearby locations')
    return entity

上述代码部分的响应是:

Error 500: Internal Server Error

Sorry,the requested URL 'http://localhost:8080/locations' caused an error:

Unsupported response type: 
  

我如何从mongo中获取该信息,因为瓶子可以作为JSON返回?

@route('/locations/:lat/:lng',method='GET')
def get_location(lat,lng):
    response.content_type = 'application/json'
    objdb = db.locations.find({'coordinate2d': {'$near': [lat,lng]}},{'coordinate2d':bool(1)}).skip(0).limit(3)
    entries = [entry for entry in objdb]
    return MongoEncoder().encode(entries)

在我的情况下,产生这个:

[
    {
        "_id": "4f4201bb7e720d1dca000005","coordinate2d": [
            33.02032100000006,-117.19483074631853
        ]
    },{
        "_id": "4f4201587e720d1dca000002","coordinate2d": [
            33.158092999999994,-117.350594
        ]
    },{
        "_id": "4f42018b7e720d1dca000003","coordinate2d": [
            33.195870000000006,-117.379483
        ]
    }
]

总结

以上是编程之家为你收集整理的Python / Bottle / MongoDB:不支持的响应类型:全部内容,希望文章能够帮你解决Python / Bottle / MongoDB:不支持的响应类型:所遇到的程序开发问题。


如果您也喜欢它,动动您的小指点个赞吧

除非注明,文章均由 laddyq.com 整理发布,欢迎转载。

转载请注明:
链接:http://laddyq.com
来源:laddyq.com
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。


联系我
置顶