应用引擎:"URLFetch is not available in this environment."

Appengine: "URLFetch is not available in this environment."

我在 Python 中构建了一个 App 引擎 API,由 Node 应用程序获取。 API 按预期工作(1)在生产中获取和 post 请求,以及(2)在开发中获取请求。它在 post 开发请求中失败,我可以使用一些帮助来找出原因。

错误信息

在我的节点环境中,我看到错误:

No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:4444' is therefore not allowed access. The response had HTTP status code 500. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.

但我已经在我的应用程序中使用了 flask_cors 包,所以我想知道这是否真的是 CORS 问题。

我激活的虚拟python环境日志:

File "/myproject/googleAdsApi/env/lib/python2.7/site-packages/urllib3/contrib/appengine.py", line 103, in init "URLFetch is not available in this environment.")

所以也许我应该在我的虚拟环境中使用 URLFetch 的替代方法?

我当前的实现

正在获取:

fetch('http://localhost:8080/api/get_accounts', {
    method: "POST",
    mode: "cors", 
    cache: "no-cache", 
    credentials: "same-origin", 
    headers: {
        "Content-Type": "application/json; charset=utf-8",
    },
    redirect: "follow", 
    referrer: "no-referrer", 
    body: JSON.stringify(credentials)
})
.then(response => response.json())
.then(result => console.log(result));

flask_cors:

app = Flask(__name__)
cors = CORS(app, resources={r"/api/*": {"origins": "*"}})

始终使用 dev_appserver.py 作为 运行 您在 GAE 应用程序上的本地开发环境。 GAE 有很多难以在本地 virtualenv 上手动重现的特性。此外,您还可以获得许多有用的工具来监控各种服务(任务队列、内存缓存、存储等)。 dev_appserver.py 还会自动加载大量 GAE 本机 api 供您使用,而且它们通常有自己的流行库版本,适用于无服务器环境(URLFetch 就是其中之一)

官方文档 https://cloud.google.com/appengine/docs/standard/python/tools/using-local-server