当客户端通过send_file命令调用服务器的Flask端点时,无法查看映像

2024-04-25 08:28:26 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个用python运行的Flask应用程序。有一个客户端正在从磁盘提供映像服务。我想一个服务器,以达到一个终点,并检索图像

在客户方面:

@app.route('/api/get_image')
def get(self, id):
   # Map id to filename.
   return send_file(filename)

当我从浏览器调用客户机的端点时,这种方法就起作用了

在服务器端,我有一个类似的函数,应该调用上面的端点

@app.route('/api/get_image')
def get(self, id):
    return requests.get(client_url + '/api/get_image')

当我调用服务器端点时,我得到:

TypeError: <Response [200]> is not JSON serializable

但即使我尝试使用.json(),它也不起作用。如何返回图像有效负载