python - 编写API时,遇到504错误,如何正确处理
怪我咯
怪我咯 2017-04-18 10:22:52
0
2
644

自己写了个测试数据库连接的API,发现本地测试时,数据库的ip地址错误可以正常返回自己定义的错误,但是放到自己的服务器上测试,发现请求会超时,并且返回html格式的504错误.后端是采取python,flask,部署是结合uwsgi和Nginx。

怪我咯
怪我咯

走同样的路,发现不同的人生

reply all(2)
洪涛

The 504 error is that the server is acting as a gateway or proxy to complete the client's request, because the background code may have accessed another server. I am accessing a remote database here, so in order to complete the request, the server accesses the server of this remote database. , but did not get a timely response. Because it cooperated with Nginx, the timeout set for a request was 60s. Within this time period, there was still no timely response and a 504 error was returned. I set the timeout for connecting to the remote database to be within 60 seconds, so that it can return error information, and the exception will be caught by my background, and then return my own defined error format.

Peter_Zhu

The server returns 504 indicating that it did not respond to the request. There may be an unexpected error

Check the business logic and return a response to the front end for each situation, preferably with error information

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template