【发布时间】:2020-10-19 04:32:42
【问题描述】:
我在 JSON 正文中有字节作为数据输入。我不知道如何在 JSON 中格式化,所以 API 会接受它。部分 API 函数会将输入的字节通过 base64 进行序列化,以便 TensorFlow 模型可以返回预测,也就是 API 的输出。
TypeError: 'abc' 的类型为
解析体
{
"cc": "b'abc'",
"pt": "b'def'",
"project": "xxx",
"model": "xxx",
"signature": "xxx",
"version": "xxx"
}
输入的字节是通过下面的函数通过Base64序列化,以便tensorflow返回预测。
def get_serialized_example(raw):
return tf.train.Example(
features=tf.train.Features(
feature={"value":
tf.train.Feature(bytes_list=tf.train.BytesList(value=[raw]))
}
)
).SerializeToString()
b64_country_code = base64.b64encode(get_serialized_example(request.country_code)).decode('utf-8')
b64_project_type = base64.b64encode(get_serialized_example(request.project_type)).decode('utf-8')
【问题讨论】:
-
我们需要比这更多的信息。请参阅How to Ask、help center。
-
我已经更新了我的帖子/。 @AMC
标签: python json api rest postman