首页 > 解决方案 > 错误,“[错误] 33#33: *92500 connect() failed (111: Connection denied) while connection to upstream, client: 216.58.212.244, server: #1906

问题描述

尝试使用 FastAPI 在 App Engine 上托管 API,最初使用的是 Flask,它可以工作但速度很慢。我现在收到以下错误:error, "[error] 33#33: *92500 connect() failed (111: Connection refused) while connecting to upstream, client: 216.58.212.244, server:

这是 app.yaml 文件:

runtime: python
env: flex

entrypoint: uvicorn --host 127.0.0.1 --port 8080 --timeout-keep-alive 500 main:app
service: default

instance_class: F4_1G

# Instance Class: F4_1G
# Memory Limit: 2048 MB
# CPU Limit: 2.4 GHz
# Supported Scaling Types: Automatic

runtime_config:
    python_version: 3

handlers:
- url: /.*
  script: auto

network:
  forwarded_ports:
   - 8080

这是主脚本,必须删除大部分代码:

import uvicorn
from fastapi import FastAPI, Request
app = FastAPI()

@app.get('/')
async def nlp_email(return_method : str,
                    user_email    : str,
                    filename      : str)

    return {'html': html}

标签: pythongoogle-app-enginefastapi

解决方案


您将应用程序绑定在 127.0.0.1 网络接口上,这意味着它只能在 localhost 上访问。

要使您的应用程序绑定到所有可用的网络接口,您可以使用 0.0.0.0

entrypoint: uvicorn --host 0.0.0.0 --port 8080 --timeout-keep-alive 500 main:app

推荐阅读