Python Azure ML studio web服务序列化

Python Azure ML studio web服务序列化,python,web-services,azure-machine-learning-studio,Python,Web Services,Azure Machine Learning Studio,我试图从azureml中的Python笔记本中设置一个web服务,并希望它返回一个{string:float}字典。浮点数可以很好地序列化,但字符串不能 这是我正在使用的函数: def demoservice(N, Vy, My): X = scaler.fit_transform([N, Vy, My]) res = clf.predict(X) a = [ {'diam': x[0], 'radius': x[1], 'thickness': x[2]} for x

我试图从azureml中的Python笔记本中设置一个web服务,并希望它返回一个{string:float}字典。浮点数可以很好地序列化,但字符串不能

这是我正在使用的函数:

def demoservice(N, Vy, My):
    X = scaler.fit_transform([N, Vy, My])
    res = clf.predict(X)
    a = [ {'diam': x[0], 'radius': x[1], 'thickness': x[2]} for x in res]
    return a
电话:

demoservice("140", "100", "0")
正确返回:

[{'diam': 16.0, 'radius': 2.0, 'thickness': 5.0}]
但是web调用返回此json响应:

{"Results":{"output1":{"type":"table","value":{"Values":[["{\"type\": \"list\", \"value\": [{\"type\": \"dict\", \"value\": [[{\"type\": \"bytes\", \"value\": \"ZGlhbQ==\"}, {\"type\": \"float\", \"value\": \"16.0\"}], [{\"type\": \"bytes\", \"value\": \"cmFkaXVz\"}, {\"type\": \"float\", \"value\": \"2.0\"}], [{\"type\": \"bytes\", \"value\": \"dGhpY2tuZXNz\"}, {\"type\": \"float\", \"value\": \"5.0\"}]]}]}"]]}},"output2":{"type":"table","value":{"Values":[["data:text/plain,Execution OK\r\n",null]]}}}}
如您所见,在响应中,字典的键没有被正确序列化。例如:

{\"type\": \"bytes\", \"value\": \"cmFkaXVz\"}

这里我使用了
cmFkaXVz
而不是可读的值。

它以这种方式返回,因为它使用文字引号字符进行响应。我采取的解决方法是在json响应上使用
string.replace('\\','')
。@Wes我认为他指的不是这个。事实上,字符串没有正确的值。@alexlomba87您指出了这一点,这一点似乎很明显。作为回应,我在过去遇到过Azure web服务将字符串响应序列化为base64字节字符串的问题。在
{\'type\':\'bytes\',\'value\':\'cmFkaXVz\'}
的情况下,我能够重用我的一个逻辑应用程序中的解析行。通过设置
byte\u string='\'cmFkaXVz\'
,我可以使用
base64.b64解码(byte\u string.replace('\\\','')来获取值。