【问题标题】:In AWS Step Function State Machines, how do you enable JsonParser.Feature.ALLOW_NON_NUMERIC_NUMBERS在 AWS Step Function 状态机中,如何启用 JsonParser.Feature.ALLOW_NON_NUMERIC_NUMBERS
【发布时间】:2021-05-15 16:21:27
【问题描述】:

当调用负载中包含float('nan') 的状态机时,由于Non-standard token 'NaN',结果提示启用JsonParser.Feature.ALLOW_NON_NUMERIC_NUMBERS

import boto3
import json
client = boto3.client('stepfunctions', endpoint_url=endpoint_url)
client.start_sync_execution(stateMachineArn='state_machine_arn',
                            name='new-execution',
                            input=json.dumps({'foo': float('nan')})

(截断)

InvalidExecutionInput                     Traceback (most recent call last)
...
~/opt/miniconda3/envs/pandars38/lib/python3.8/site-packages/botocore/client.py in _make_api_call(self, operation_name, api_params)
    674             error_code = parsed_response.get("Error", {}).get("Code")
    675             error_class = self.exceptions.from_code(error_code)
--> 676             raise error_class(parsed_response, operation_name)
    677         else:
    678             return parsed_response

InvalidExecutionInput: An error occurred (InvalidExecutionInput) when calling the StartSyncExecution operation: Invalid State Machine Execution Input: 'Non-standard token 'NaN': enable JsonParser.Feature.ALLOW_NON_NUMERIC_NUMBERS to allow'

(包装)

InvalidExecutionInput: 
    An error occurred (InvalidExecutionInput) when calling the StartSyncExecution operation: 
    Invalid State Machine Execution Input: 
    'Non-standard token 'NaN': enable JsonParser.Feature.ALLOW_NON_NUMERIC_NUMBERS to allow'

同样的异常也发生在 numpy np.nan 上。

【问题讨论】:

  • 嗨,不确定这是否会引起兴趣 forums.aws.amazon.com/message.jspa?messageID=761953 或者可能将类型更改为字符串以便可以包含像 NaN 这样的非标准值?
  • 谢谢,是的,现在我只是将任何 NaN 更改为基本上 null ,但只是好奇是否有人知道如何访问这个神秘的 JsonParser.Feature.ALLOW_NON_NUMERIC_NUMBERS 哈哈。

标签: python json python-3.x state-machine aws-step-functions


【解决方案1】:

根据官方 JSON 规范,NaN 不是有效的 JSON 值。 https://www.json.org/json-en.html

Step Functions 仅支持符合官方 JSON 规范的标准令牌。

我建议将您的 NaN 编码为 null。

【讨论】:

  • 是的,使用该解决方法,但我特别想知道错误消息是如何说“启用 JsonParser.Feature.ALLOW_NON_NUMERIC_NUMBERS 以允许”,所以我不知道这是否是一个超低级错误我们无法控制,只是好奇。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-07-26
  • 2022-09-23
  • 1970-01-01
  • 2022-11-03
  • 1970-01-01
相关资源
最近更新 更多