gpt4 book ai didi

Python/瓶/MongoDB : Unsupported response type:

转载 作者:太空狗 更新时间:2023-10-30 01:16:56 26 4
gpt4 key购买 nike

@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: <type 'dict'>

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

最佳答案

我在尝试返回 python 列表时遇到此错误。我以为它会翻译成 JSON,但事实并非如此。它到达了 bottle.py 中处理可迭代对象的那一行,并找到了列表中的第一个字典并抛出了上面的错误。

为了解决这个问题,我只是将我的列表嵌入到字典中。

return {'response': []}

关于Python/瓶/MongoDB : Unsupported response type: <type 'dict' >,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9358480/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com