Flask RESTful API请求,管道损坏[Errno 32]! [英] Flask RESTful API request, Broken pipe [Errno 32] !

查看:144
本文介绍了Flask RESTful API请求,管道损坏[Errno 32]!的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Web开发的新手,我正在尝试使用Flask微框架创建RESTful Web服务.

I'm new to web development and I'm trying to create a RESTful web service using the Flask micro-framework.

这是我的代码:

app = Flask(__name__)       

client = MongoClient()
db = client.markets

def toJson(data):
    return json.dumps(data, default=json_util.default)

@app.route('/', methods=['GET'])

def get_tasks():
    cursor = db.europe.find()
    list = []

    for i in cursor:
        list.append(i)

    return toJson(list)

当我从浏览器发送请求时,它一直在等待服务器,并且不返回任何内容.

When I send the request from my browser, it is constantly waiting for the server and nothing is returned.

最终,我将看到在终端中运行的flask服务器会给我:[Errno 32]管道损坏.

Eventually I will see the flask server running in the terminal will give me: [Errno 32] Broken pipe.

我的收藏有150万个条目,每个条目都有大约20个属性.可能是因为请求太大?

My collection has 1.5 million entries, each with about 20 attributes. Could it be because the request is too large?

先谢谢了.

推荐答案

断开的管道表示 socket pipe 您的烧瓶过程想要交谈的消息已经死亡.考虑到您正在与数据库进行交互,很可能数据库已终止连接或由于其他原因导致连接终止.

The Broken pipe indicates that the other end of a socket or pipe that your flask process wants to talk to has died. Considering that you are interacting with the database it's very likely that the database has terminated the connection or the connection has died for other reasons.

也许您应该分析在数据库上运行的查询,因为代码本身似乎没有明显的问题.

Probably you should be analyzing the query that you run on your db, because the code itself doesn't seem to have an obvious problem.

尝试在 MongoDB 上手动运行查询,然后看看会发生什么.查询是否成功返回?

Try running the query on your MongoDB manually and see what happens. Does the query return successfully?

您提到的是要花费很多时间才能得到该错误.可能是某些索引丢失或在您的模式中未正确使用,这会使查询执行非常慢,并且在等待了很长时间后达到了超时(fe maxTimeMS )?

You're mentioning that it takes a lot of time until you get that error. Could it be that some indexes are missing or not properly used in your schema, which makes the query execute very slow, and after waiting for a long time it reaches a timeout (f.e. maxTimeMS)?

这篇关于Flask RESTful API请求,管道损坏[Errno 32]!的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆