gpt4 book ai didi

python - 在 AWS Step Function 状态机中,如何启用 JsonParser.Feature.ALLOW_NON_NUMERIC_NUMBERS

转载 作者:行者123 更新时间:2023-12-05 06:51:26 24 4
gpt4 key购买 nike

当在负载中使用 float('nan') 调用状态机时,结果提示启用 JsonParser.Feature.ALLOW_NON_NUMERIC_NUMBERS 因为 非标准 token “NaN” .

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 上。

最佳答案

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

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

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

关于python - 在 AWS Step Function 状态机中,如何启用 JsonParser.Feature.ALLOW_NON_NUMERIC_NUMBERS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66162996/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com