Home  >  Q&A  >  body text

python - 编写API时,遇到504错误,如何正确处理

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

怪我咯怪我咯2740 days ago614

reply all(2)I'll reply

  • PHP中文网

    PHP中文网2017-04-18 10:24:52

    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.

    reply
    0
  • 天蓬老师

    天蓬老师2017-04-18 10:24:52

    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

    reply
    0
  • Cancelreply