小编Joh*_*yer的帖子

Google App Engine:通过 Python 使用自定义入口点

我开始学习 Google App Engine,并使用 Flask 应用程序编写了一个基本的 main.py 文件,该文件运行良好。这是前几行代码:

from flask import Flask, jsonify

app = Flask(__name__)

@app.route("/")
def root():
    return jsonify({'status': "Success!"}), 200
Run Code Online (Sandbox Code Playgroud)

我想更改脚本的名称,因此我将其重命名为“test-app.py”并将此行添加到 app.yaml 中:

runtime: python38
entrypoint: test-app:app
Run Code Online (Sandbox Code Playgroud)

然后重新运行 gcloud app 部署。部署成功,但应用程序返回 500,日志中显示以下内容:

2021-05-09 22:23:40 default[20210509t222122]  "GET / HTTP/1.1" 500
2021-05-09 22:23:41 default[20210509t222122]  /bin/sh: 1: exec: test-app:app: not found
Run Code Online (Sandbox Code Playgroud)

我还从文档中尝试了这些:

entrypoint: gunicorn -b :$PORT test-app:app
entrypoint: uwsgi --http :$PORT --wsgi-file test-app.py --callable application
Run Code Online (Sandbox Code Playgroud)

在这两种情况下,日志均显示“/bin/sh: 1: exec: (gunicorn|uwsgi): not found”

在 Lambda 中,入口点是通过处理程序选项设置的,默认情况下,该选项是名为 lambda_function 的文件中名为 lambda_handler() 的函数。看起来 …

google-app-engine google-app-engine-python

8
推荐指数
1
解决办法
4175
查看次数

在 FastAPI 中以字典形式获取查询参数

我上个月学习了 Flask,现在正在学习 Pyramid 和 FastAPI。我的应用程序的要求之一是获取字典中的所有查询参数(有多种组合,我可以假设所有键都是唯一的并且具有单个值)

在 Flask 中,对于像GET /?foo=1&bar=2这样的请求,我可以从字典中获取 foo 和 bar 参数,如下所示:

from flask import Flask, request
app = Flask(__name__)
@app.route("/")
def root():
     if 'foo' in request.args:
         return f"foo was provided: {request.args['foo']}", 200
     else:
         return "I need your foo, fool!", 400
Run Code Online (Sandbox Code Playgroud)

我不知道如何在 FastAPI / Starlette 中轻松地做到这一点。我想出的最佳解决方案是通过拆分 request.query_params 来手动构建字典:

from fastapi import FastAPI, Request
app = FastAPI()

@app.get("/")
@app.get("/{path:path}")
def root(path, request: Request):

    request_args = {}
    if request.query_params:
        for _ in str(request.query_params).split("&"):
            [key, value] = _.split("=")
            request_args[key] = …
Run Code Online (Sandbox Code Playgroud)

python starlette fastapi

7
推荐指数
1
解决办法
2万
查看次数

在 Ubuntu 18 上安装 gcloud / gsutil

希望将一些存储桶从 AWS S3 迁移到 Google Cloud Storage,但在我的 Ubuntu 18.04.4 VM 上安装 GCP 工具却没有任何运气。

遵循本指南:[ https://cloud.google.com/storage/docs/gsutil_install#deb][1]

主要是卡在这里:

root@ubuntu18:/home/me# apt install google-cloud-sdk
Reading package lists... Done
Building dependency tree       
Reading state information... Done

No apt package "google-cloud-sdk", but there is a snap with that name.
Try "snap install google-cloud-sdk"

E: Unable to locate package google-cloud-sdk

Run Code Online (Sandbox Code Playgroud)

ubuntu apt google-cloud-platform ubuntu-18.04

2
推荐指数
1
解决办法
2577
查看次数