我使用 JSONschema 定义了一个模型并将其设置为 lambda。我可以看到模型被添加到请求正文中,如下图所示
但我还需要设置请求验证器来验证它。这是我下面的示例 AWS SAM 模板。
Resources:
Api:
Type: "AWS::Serverless::Api"
Properties:
StageName: !Ref Environment
TracingEnabled: false
EndpointConfiguration: REGIONAL
Auth:
Authorizers:
Auth:
FunctionPayloadType: TOKEN
FunctionArn: !GetAtt Auth.Arn
Identity:
Header: authorization
Models:
RegisterCat:
$schema: "http://json-schema.org/draft-04/hyper-schema#"
title: RegisterCat
type: object
properties:
name:
type: string
maxLength: 32
species:
type: string
maxLength: 32
age:
type: integer
minimum: 0
maximum: 100
required:
- name
- species
- age
RegisterCat:
Type: "AWS::Serverless::Function"
Properties:
FunctionName: !Join ["-", [example, !Ref Environment, register, cat]]
CodeUri: register_cat/
Environment:
Variables: …Run Code Online (Sandbox Code Playgroud) 当我按照此处的说明进行操作时,发生了此错误。我设置了单位文件。我了解到 LAN env value 无法正确传输,并且它使用默认的 ascii。您可以通过在单元文件中添加一行来解决此问题。这是一个非常漫长的旅程才发现......
[service]
Environment="LANG=en_US.UTF-8"
Run Code Online (Sandbox Code Playgroud)
当我使用 mod_wsgi 和 Apache2 设置环境时没有任何问题。我只需export LANG='en_US.UTF-8' export LC_ALL='en_US.UTF-8'在 /etc/apache2/envars 路径中添加“”即可上传非 ASCII 文件名的文件。
这次,我使用Nginx 和 Gunicorn设置我的环境。但是在显示非 ASCII 字符的每个部分都会发生 UnicodeEncoderError。
'ascii' codec can't encode characters in position 57-59: ordinal not in range(128)
Run Code Online (Sandbox Code Playgroud)
我不明白为什么在Python3和Django环境中使用'ascii'编解码器进行编码。
我搜索、搜索、搜索。我检查并尝试如下。
#!/home/username/venv/bin/python3在 Gunicorn 文件中检查“ ”。