小编Jay*_*und的帖子

如何使用 AWS SAM 设置请求验证器?

我使用 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)

aws-sam

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

UnicodeEncodeError [Python3/Gunicorn/Nginx/Django]

解决了

当我按照此处的说明进行操作时,发生了此错误。我设置了单位文件。我了解到 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'编解码器进行编码。

我搜索、搜索、搜索。我检查并尝试如下。

  1. PostgreSQL 检查:编码 UTF8
  2. Django默认编码:utf-8
  3. Ubuntu 语言环境检查:en_US.UTF-8(我也尝试过“ko_KR.UTF-8”,因为它与韩语有错误)
  4. 检查了 python 3 sys.getdefaultencoding、sys.stdout.encoding、sys.stdin.encoding:utf-8
  5. 添加字符集utf-8;在 /etc/nginx/sites-available/myproject 中
  6. 检查 Gunicorn 是否调用 python2 而不是 python3 :使用 pip3 virtualenv 安装 Gunicorn 并#!/home/username/venv/bin/python3在 Gunicorn 文件中检查“ ”。
  7. 在views.py中写入 import …

django nginx utf-8 python-3.x gunicorn

5
推荐指数
1
解决办法
2253
查看次数

标签 统计

aws-sam ×1

django ×1

gunicorn ×1

nginx ×1

python-3.x ×1

utf-8 ×1